Update for MKL27Z
This commit is contained in:
@@ -142,6 +142,43 @@ get_hex (struct tty *tty, const char *s, uint32_t *v_p)
|
||||
}
|
||||
|
||||
|
||||
#define TOUCH_VALUE_HIGH 195
|
||||
#define TOUCH_VALUE_LOW 150
|
||||
static void
|
||||
cmd_button (struct tty *tty, const char *line)
|
||||
{
|
||||
int i = 0;
|
||||
extern uint16_t touch_get (void);
|
||||
uint16_t v0 = 0;
|
||||
int touched = 0;
|
||||
|
||||
(void)line;
|
||||
put_line (tty, "Please touch the bear.\r\n");
|
||||
|
||||
while (i < 16)
|
||||
{
|
||||
uint16_t v = touch_get ();
|
||||
v0 = (v0 * 2 + v)/3;
|
||||
|
||||
if (touched == 0 && v0 > TOUCH_VALUE_HIGH)
|
||||
{
|
||||
tty_send (tty, "!", 1);
|
||||
touched = 1;
|
||||
}
|
||||
else if (touched == 1 && v0 < TOUCH_VALUE_LOW)
|
||||
{
|
||||
tty_send (tty, ".", 1);
|
||||
touched = 0;
|
||||
i++;
|
||||
}
|
||||
|
||||
chopstx_usec_wait (10*1000);
|
||||
}
|
||||
|
||||
tty_send (tty, "\r\n", 2);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmd_touch (struct tty *tty, const char *line)
|
||||
{
|
||||
@@ -149,7 +186,7 @@ cmd_touch (struct tty *tty, const char *line)
|
||||
extern uint16_t touch_get (void);
|
||||
|
||||
(void)line;
|
||||
put_line (tty, "Please touch the bear, type Enter to finish.\r\n");
|
||||
put_line (tty, "Please touch the bear.\r\n");
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
@@ -449,6 +486,7 @@ cmd_help (struct tty *tty, const char *line)
|
||||
|
||||
|
||||
struct command_table command_table[] = {
|
||||
{ "button", cmd_button },
|
||||
{ "touch", cmd_touch },
|
||||
{ "mdw", cmd_mdw },
|
||||
{ "mww", cmd_mww },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const unsigned int *const crc32_table= (const unsigned int *const)0x00000480;
|
||||
const unsigned int *const crc32_table= (const unsigned int *)0x00000480;
|
||||
|
||||
void
|
||||
crc32_init (unsigned int *p)
|
||||
|
||||
@@ -7,27 +7,7 @@
|
||||
#include "tty.h"
|
||||
#include "board.h"
|
||||
#include "command.h"
|
||||
|
||||
struct GPIO {
|
||||
volatile uint32_t PDOR; /* Port Data Output Register */
|
||||
volatile uint32_t PSOR; /* Port Set Output Register */
|
||||
volatile uint32_t PCOR; /* Port Clear Output Register */
|
||||
volatile uint32_t PTOR; /* Port Toggle Output Register */
|
||||
volatile uint32_t PDIR; /* Port Data Input Register */
|
||||
volatile uint32_t PDDR; /* Port Data Direction Register */
|
||||
};
|
||||
static struct GPIO *const GPIOB = (struct GPIO *const)0x400FF040;
|
||||
static struct GPIO *const GPIOD = (struct GPIO *const)0x400FF0C0;
|
||||
static struct GPIO *const GPIOE = (struct GPIO *const)0x400FF100;
|
||||
|
||||
static void
|
||||
set_led (int on)
|
||||
{
|
||||
if (on)
|
||||
GPIOB->PCOR = (1 << 0); /* PTB0: Clear: Light on */
|
||||
else
|
||||
GPIOB->PSOR = (1 << 0); /* PTB0: Set : Light off */
|
||||
}
|
||||
#include <sys.h>
|
||||
|
||||
static chopstx_mutex_t mtx;
|
||||
static chopstx_cond_t cnd0;
|
||||
|
||||
@@ -19,7 +19,7 @@ struct TPM {
|
||||
volatile uint32_t CONF;
|
||||
};
|
||||
|
||||
static struct TPM *const TPM1 = (struct TPM *const)0x40039000;
|
||||
static struct TPM *const TPM1 = (struct TPM *)0x40039000;
|
||||
|
||||
static chopstx_intr_t tpm1_intr;
|
||||
#define INTR_REQ_TPM1 18
|
||||
@@ -36,8 +36,14 @@ touch_get (void)
|
||||
| (0<<0) /* puddselect= 0 */
|
||||
;
|
||||
|
||||
/*
|
||||
* Start the timer's counter.
|
||||
* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=011.
|
||||
*/
|
||||
TPM1->SC = 0xcb;
|
||||
|
||||
/* Let the register to pull it up. */
|
||||
PORTB->PCR1 = (1<<3) /* TPM1_CH1 */
|
||||
PORTB->PCR1 = (3<<8) /* TPM1_CH1 */
|
||||
| (0<<6) /* DriveStrengthEnable=0 */
|
||||
| (0<<4) /* PassiveFilterEnable=0 */
|
||||
| (1<<2) /* SlewRateEnable = slow */
|
||||
@@ -46,8 +52,10 @@ touch_get (void)
|
||||
;
|
||||
|
||||
chopstx_intr_wait (&tpm1_intr);
|
||||
/* Clear overflow. */
|
||||
TPM1->SC |= 0x80;
|
||||
/* Clear overflow and CH1 capture. */
|
||||
TPM1->STATUS = 0x102;
|
||||
/* Stop the counter. */
|
||||
TPM1->SC = 0;
|
||||
|
||||
return TPM1->C1V;
|
||||
}
|
||||
@@ -58,21 +66,13 @@ touch_init (void)
|
||||
{
|
||||
chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1);
|
||||
|
||||
/* 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;
|
||||
/* Rising edge: ELSB=0 ELSA=1 */
|
||||
TPM1->C1SC = 0x84;
|
||||
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;
|
||||
|
||||
touch_get ();
|
||||
/* No trigger. */
|
||||
/* Stop on overflow: CSOO=1 */
|
||||
/* Run the timer in the debug mode */
|
||||
TPM1->CONF = 0x000200c0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user