diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2016-07-01 10:58:05 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2016-07-01 10:58:05 +0900 |
commit | 1f23bd4048610ce98f3a77e28feff8a0cd346208 (patch) | |
tree | aa787a59eac6f72f5fc684da035a15df84440dbc /example-fs-bb48 | |
parent | f5880ee5d5559d45771e4a626c54309c88f437e7 (diff) |
Change touch button for MKL27Z
Diffstat (limited to 'example-fs-bb48')
-rw-r--r-- | example-fs-bb48/command.c | 4 | ||||
-rw-r--r-- | example-fs-bb48/touch.c | 34 |
2 files changed, 26 insertions, 12 deletions
diff --git a/example-fs-bb48/command.c b/example-fs-bb48/command.c index 1a6582c..485b116 100644 --- a/example-fs-bb48/command.c +++ b/example-fs-bb48/command.c @@ -142,8 +142,8 @@ get_hex (struct tty *tty, const char *s, uint32_t *v_p) } -#define TOUCH_VALUE_HIGH 195 -#define TOUCH_VALUE_LOW 150 +#define TOUCH_VALUE_HIGH 100 +#define TOUCH_VALUE_LOW 50 static void cmd_button (struct tty *tty, const char *line) { diff --git a/example-fs-bb48/touch.c b/example-fs-bb48/touch.c index 960692e..d22f5e7 100644 --- a/example-fs-bb48/touch.c +++ b/example-fs-bb48/touch.c @@ -24,22 +24,28 @@ static struct TPM *const TPM1 = (struct TPM *)0x40039000; static chopstx_intr_t tpm1_intr; #define INTR_REQ_TPM1 18 -uint16_t -touch_get (void) +static void +gpio_assert_low (void) { - chopstx_prio_t prio_old; - - prio_old = chopstx_setpriority (CHOPSTX_PRIO_INHIBIT_PREEMPTION); - /* Assert LOW. */ PORTB->PCR1 = (1<<8) /* GPIO */ | (0<<6) /* DriveStrengthEnable=0 */ | (0<<4) /* PassiveFilterEnable=0 */ | (1<<2) /* SlewRateEnable = slow */ | (0<<1) /* pull enable = 0 */ - | (0<<0) /* puddselect= 0 */ + | (0<<0) /* pull up select= 0 */ ; + GPIOB->PCOR = (1 << 1); /* PTB1: Clear: Output 0 */ +} + +uint16_t +touch_get (void) +{ + chopstx_prio_t prio_old; + uint16_t v; + + prio_old = chopstx_setpriority (CHOPSTX_PRIO_INHIBIT_PREEMPTION); /* * Start the timer's counter. * TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=011. @@ -52,18 +58,23 @@ touch_get (void) | (0<<4) /* PassiveFilterEnable=0 */ | (1<<2) /* SlewRateEnable = slow */ | (0<<1) /* pull enable = 0 */ - | (0<<0) /* puddselect= 0 */ + | (0<<0) /* pullup select= 0 */ ; chopstx_setpriority (prio_old); chopstx_intr_wait (&tpm1_intr); + gpio_assert_low (); + + v = TPM1->C1V; + /* Clear overflow and CH1 capture. */ TPM1->STATUS = 0x102; - /* Stop the counter. */ + /* Stop the timer. */ TPM1->SC = 0; + TPM1->CNT = 0xffff; /* Writing causes reset of the counter. */ - return TPM1->C1V; + return v; } @@ -81,4 +92,7 @@ touch_init (void) /* Stop on overflow: CSOO=1 */ /* Run the timer in the debug mode */ TPM1->CONF = 0x000200c0; + + TPM1->CNT = 0xffff; /* Writing causes reset of the counter. */ + gpio_assert_low (); } |