Update example for fs-bb48
This commit is contained in:
@@ -6,7 +6,7 @@ PROJECT = sample
|
||||
|
||||
CHOPSTX = ..
|
||||
LDSCRIPT= sample.ld
|
||||
CSRC = sample.c usb-cdc.c command.c
|
||||
CSRC = sample.c usb-cdc.c command.c touch.c
|
||||
CHIP=mkl27z
|
||||
|
||||
USE_SYS = yes
|
||||
|
||||
@@ -51,7 +51,6 @@ static char hexchar (uint8_t x)
|
||||
return '?';
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DECIMAL_OUTPUT
|
||||
static char *
|
||||
compose_decimal (char *s, int value)
|
||||
{
|
||||
@@ -87,7 +86,7 @@ compose_decimal (char *s, int value)
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static char *
|
||||
compose_hex (char *s, uint32_t v)
|
||||
@@ -143,6 +142,31 @@ get_hex (struct tty *tty, const char *s, uint32_t *v_p)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmd_touch (struct tty *tty, const char *line)
|
||||
{
|
||||
int i;
|
||||
extern uint16_t touch_get (void);
|
||||
|
||||
(void)line;
|
||||
put_line (tty, "Please touch the bear, type Enter to finish.\r\n");
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
uint16_t v;
|
||||
char output[8];
|
||||
char *s;
|
||||
|
||||
chopstx_usec_wait (1000*1000);
|
||||
v = touch_get ();
|
||||
s = compose_decimal (output, v);
|
||||
*s++ = '\r';
|
||||
*s++ = '\n';
|
||||
tty_send (tty, output, s - output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmd_mdw (struct tty *tty, const char *line)
|
||||
{
|
||||
@@ -425,6 +449,7 @@ cmd_help (struct tty *tty, const char *line)
|
||||
|
||||
|
||||
struct command_table command_table[] = {
|
||||
{ "touch", cmd_touch },
|
||||
{ "mdw", cmd_mdw },
|
||||
{ "mww", cmd_mww },
|
||||
{ "fes", cmd_fes },
|
||||
|
||||
@@ -117,6 +117,8 @@ static char hexchar (uint8_t x)
|
||||
}
|
||||
|
||||
|
||||
extern void touch_init (void);
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
@@ -144,6 +146,8 @@ main (int argc, const char *argv[])
|
||||
|
||||
u = 1;
|
||||
|
||||
touch_init ();
|
||||
|
||||
tty = tty_open ();
|
||||
tty_wait_configured (tty);
|
||||
|
||||
|
||||
89
example-fs-bb48/touch.c
Normal file
89
example-fs-bb48/touch.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <chopstx.h>
|
||||
#include <mcu/mkl27z.h>
|
||||
|
||||
struct TPM {
|
||||
volatile uint32_t SC;
|
||||
volatile uint32_t CNT;
|
||||
volatile uint32_t MOD;
|
||||
volatile uint32_t C0SC;
|
||||
volatile uint32_t C0V;
|
||||
volatile uint32_t C1SC;
|
||||
volatile uint32_t C1V;
|
||||
uint32_t rsvd0[14];
|
||||
volatile uint32_t STATUS;
|
||||
uint32_t rsvd1[7];
|
||||
volatile uint32_t POL;
|
||||
uint32_t rsvd2[4];
|
||||
volatile uint32_t CONF;
|
||||
};
|
||||
|
||||
static struct TPM *const TPM1 = (struct TPM *const)0x40039000;
|
||||
|
||||
static chopstx_intr_t tpm1_intr;
|
||||
#define INTR_REQ_TPM1 18
|
||||
|
||||
void
|
||||
touch_init (void)
|
||||
{
|
||||
chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1);
|
||||
|
||||
PORTB->PCR1 = (1<<3) /* TPM1_CH1 */
|
||||
| (0<<6) /* DriveStrengthEnable=0 */
|
||||
| (0<<4) /* PassiveFilterEnable=0 */
|
||||
| (1<<2) /* SlewRateEnable = slow */
|
||||
| (0<<1) /* pull enable = 0 */
|
||||
| (0<<0) /* puddselect= 0 */
|
||||
;
|
||||
|
||||
/* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=000. */
|
||||
TPM1->SC = 0xc4;
|
||||
|
||||
/* Input capture mode: MSB = 0, MSA = 0 */
|
||||
/* Rising edge: ELSB=0 ELSA=1 */
|
||||
TPM1->C1SC = 0x82;
|
||||
TPM1->POL=0;
|
||||
|
||||
/* Triggered by TPM1_CH1. */
|
||||
/* channel 1: TRGSEL=0010 */
|
||||
/* external: TRGSRC=0 */
|
||||
/* active low:TRGPOL=1 */
|
||||
/* stop on overflow: CSOO=1 */
|
||||
/* start on trigger: CSOT=1 */
|
||||
TPM1->CONF = 0x02c30000;
|
||||
|
||||
/* Wait overflow. */
|
||||
chopstx_intr_wait (&tpm1_intr);
|
||||
|
||||
/* Clear overflow. */
|
||||
TPM1->SC |= 0x80;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
touch_get (void)
|
||||
{
|
||||
/* 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 */
|
||||
;
|
||||
|
||||
/* Let the register to pull it up. */
|
||||
PORTB->PCR1 = (1<<3) /* TPM1_CH1 */
|
||||
| (0<<6) /* DriveStrengthEnable=0 */
|
||||
| (0<<4) /* PassiveFilterEnable=0 */
|
||||
| (1<<2) /* SlewRateEnable = slow */
|
||||
| (0<<1) /* pull enable = 0 */
|
||||
| (0<<0) /* puddselect= 0 */
|
||||
;
|
||||
|
||||
chopstx_intr_wait (&tpm1_intr);
|
||||
/* Clear overflow. */
|
||||
TPM1->SC |= 0x80;
|
||||
|
||||
return TPM1->C1V;
|
||||
}
|
||||
@@ -686,7 +686,10 @@ tty_main (void *arg)
|
||||
|
||||
while (1)
|
||||
{
|
||||
chopstx_poll (NULL, 1, &usb_intr);
|
||||
struct chx_poll_head *pd_array[1] = {
|
||||
(struct chx_poll_head *)&usb_intr
|
||||
};
|
||||
chopstx_poll (NULL, 1, pd_array);
|
||||
if (usb_intr.ready)
|
||||
{
|
||||
uint8_t ep_num;
|
||||
@@ -919,7 +922,10 @@ tty_recv (struct tty *t, char *buf, uint32_t *timeout)
|
||||
|
||||
while (1)
|
||||
{
|
||||
chopstx_poll (timeout, 1, &poll_desc);
|
||||
struct chx_poll_head *pd_array[1] = {
|
||||
(struct chx_poll_head *)&poll_desc
|
||||
};
|
||||
chopstx_poll (timeout, 1, pd_array);
|
||||
chopstx_mutex_lock (&t->mtx);
|
||||
r = check_rx (t);
|
||||
chopstx_mutex_unlock (&t->mtx);
|
||||
|
||||
Reference in New Issue
Block a user