efm8 usb bridge working
This commit is contained in:
@@ -34,6 +34,7 @@ extern void enter_DefaultMode_from_RESET(void) {
|
||||
EMU_enter_DefaultMode_from_RESET();
|
||||
CMU_enter_DefaultMode_from_RESET();
|
||||
USART0_enter_DefaultMode_from_RESET();
|
||||
USART1_enter_DefaultMode_from_RESET();
|
||||
CRYOTIMER_enter_DefaultMode_from_RESET();
|
||||
PORTIO_enter_DefaultMode_from_RESET();
|
||||
// [Config Calls]$
|
||||
@@ -129,6 +130,9 @@ extern void CMU_enter_DefaultMode_from_RESET(void) {
|
||||
/* Enable clock for USART0 */
|
||||
CMU_ClockEnable(cmuClock_USART0, true);
|
||||
|
||||
/* Enable clock for USART1 */
|
||||
CMU_ClockEnable(cmuClock_USART1, true);
|
||||
|
||||
/* Enable clock for GPIO by default */
|
||||
CMU_ClockEnable(cmuClock_GPIO, true);
|
||||
|
||||
@@ -321,18 +325,85 @@ extern void USART1_enter_DefaultMode_from_RESET(void) {
|
||||
// [USART_InitAsync]$
|
||||
|
||||
// $[USART_InitSync]
|
||||
USART_InitSync_TypeDef initsync = USART_INITSYNC_DEFAULT;
|
||||
|
||||
initsync.enable = usartDisable;
|
||||
initsync.baudrate = 100000;
|
||||
initsync.databits = usartDatabits8;
|
||||
initsync.master = 1;
|
||||
initsync.msbf = 1;
|
||||
initsync.clockMode = usartClockMode0;
|
||||
#if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
|
||||
initsync.prsRxEnable = 0;
|
||||
initsync.prsRxCh = 0;
|
||||
initsync.autoTx = 0;
|
||||
#endif
|
||||
|
||||
USART_InitSync(USART1, &initsync);
|
||||
// [USART_InitSync]$
|
||||
|
||||
// $[USART_InitPrsTrigger]
|
||||
USART_PrsTriggerInit_TypeDef initprs = USART_INITPRSTRIGGER_DEFAULT;
|
||||
|
||||
initprs.rxTriggerEnable = 0;
|
||||
initprs.txTriggerEnable = 0;
|
||||
initprs.prsTriggerChannel = usartPrsTriggerCh0;
|
||||
|
||||
USART_InitPrsTrigger(USART1, &initprs);
|
||||
// [USART_InitPrsTrigger]$
|
||||
|
||||
// $[USART_InitIO]
|
||||
/* Set up CLK pin */
|
||||
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_CLKLOC_MASK))
|
||||
| USART_ROUTELOC0_CLKLOC_LOC11;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_CLKPEN;
|
||||
|
||||
/* Disable CS pin */
|
||||
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_CSLOC_MASK))
|
||||
| USART_ROUTELOC0_CSLOC_LOC0;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_CSPEN);
|
||||
|
||||
/* Disable CTS pin */
|
||||
USART1->ROUTELOC1 = (USART1->ROUTELOC1 & (~_USART_ROUTELOC1_CTSLOC_MASK))
|
||||
| USART_ROUTELOC1_CTSLOC_LOC0;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_CTSPEN);
|
||||
|
||||
/* Disable RTS pin */
|
||||
USART1->ROUTELOC1 = (USART1->ROUTELOC1 & (~_USART_ROUTELOC1_RTSLOC_MASK))
|
||||
| USART_ROUTELOC1_RTSLOC_LOC0;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_RTSPEN);
|
||||
|
||||
/* Set up RX pin */
|
||||
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_RXLOC_MASK))
|
||||
| USART_ROUTELOC0_RXLOC_LOC11;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_RXPEN;
|
||||
|
||||
/* Set up TX pin */
|
||||
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_TXLOC_MASK))
|
||||
| USART_ROUTELOC0_TXLOC_LOC11;
|
||||
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_TXPEN;
|
||||
|
||||
// [USART_InitIO]$
|
||||
|
||||
// $[USART_Misc]
|
||||
/* Disable CTS */
|
||||
USART1->CTRLX = USART1->CTRLX & (~USART_CTRLX_CTSEN);
|
||||
/* Set CTS active low */
|
||||
USART1->CTRLX = USART1->CTRLX & (~USART_CTRLX_CTSINV);
|
||||
/* Set RTS active low */
|
||||
USART1->CTRLX = USART1->CTRLX & (~USART_CTRLX_RTSINV);
|
||||
/* Set CS active low */
|
||||
USART1->CTRL = USART1->CTRL & (~USART_CTRL_CSINV);
|
||||
/* Set TX active high */
|
||||
USART1->CTRL = USART1->CTRL & (~USART_CTRL_TXINV);
|
||||
/* Set RX active high */
|
||||
USART1->CTRL = USART1->CTRL & (~USART_CTRL_RXINV);
|
||||
// [USART_Misc]$
|
||||
|
||||
// $[USART_Enable]
|
||||
|
||||
/* Enable USART if opted by user */
|
||||
USART_Enable(USART1, usartEnable);
|
||||
// [USART_Enable]$
|
||||
|
||||
}
|
||||
@@ -526,6 +597,21 @@ extern void PORTIO_enter_DefaultMode_from_RESET(void) {
|
||||
// [Port B Configuration]$
|
||||
|
||||
// $[Port C Configuration]
|
||||
|
||||
/* Pin PC6 is configured to Push-pull */
|
||||
GPIO_PinModeSet(gpioPortC, 6, gpioModePushPull, 1);
|
||||
|
||||
/* Pin PC7 is configured to Input enabled with pull-up */
|
||||
GPIO_PinModeSet(gpioPortC, 7, gpioModeInputPull, 1);
|
||||
|
||||
/* Pin PC8 is configured to Push-pull */
|
||||
GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull, 1);
|
||||
|
||||
/* Pin PC9 is configured to Input enabled with pull-up */
|
||||
GPIO_PinModeSet(gpioPortC, 9, gpioModeInputPull, 1);
|
||||
|
||||
/* Pin PC10 is configured to Push-pull */
|
||||
GPIO_PinModeSet(gpioPortC, 10, gpioModePushPull, 1);
|
||||
// [Port C Configuration]$
|
||||
|
||||
// $[Port D Configuration]
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "em_chip.h"
|
||||
#include "em_gpio.h"
|
||||
#include "em_usart.h"
|
||||
|
||||
#include "cbor.h"
|
||||
#include "log.h"
|
||||
@@ -61,7 +62,8 @@ int ctap_user_presence_test()
|
||||
// data is HID_MESSAGE_SIZE long in bytes
|
||||
void ctaphid_write_block(uint8_t * data)
|
||||
{
|
||||
dump_hex(data, HID_MESSAGE_SIZE);
|
||||
printf1(TAG_DUMP,"<< "); dump_hex1(TAG_DUMP, data, HID_MESSAGE_SIZE);
|
||||
usbhid_send(data);
|
||||
}
|
||||
|
||||
void heartbeat()
|
||||
@@ -83,13 +85,37 @@ void usbhid_init()
|
||||
|
||||
}
|
||||
|
||||
static int msgs_to_recv = 0;
|
||||
|
||||
int usbhid_recv(uint8_t * msg)
|
||||
{
|
||||
int i;
|
||||
if (msgs_to_recv)
|
||||
{
|
||||
GPIO_PinOutClear(gpioPortC,10);
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
msg[i] = USART_SpiTransfer(USART1, 0);
|
||||
delay(1);
|
||||
}
|
||||
msgs_to_recv--;
|
||||
// printf(">> ");
|
||||
// dump_hex(msg,64);
|
||||
return 64;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbhid_send(uint8_t * msg)
|
||||
{
|
||||
int i;
|
||||
GPIO_PinOutSet(gpioPortC,10);
|
||||
for (i = 0; i < HID_MESSAGE_SIZE; i++)
|
||||
{
|
||||
USART_SpiTransfer(USART1, *msg++);
|
||||
}
|
||||
GPIO_PinOutClear(gpioPortC,10);
|
||||
}
|
||||
|
||||
void usbhid_close()
|
||||
@@ -100,6 +126,29 @@ void main_loop_delay()
|
||||
{
|
||||
}
|
||||
|
||||
void delay(int ms)
|
||||
{
|
||||
int t1 = millis();
|
||||
while(millis() - t1 < ms)
|
||||
;
|
||||
}
|
||||
|
||||
void GPIO_ODD_IRQHandler()
|
||||
{
|
||||
uint32_t flag = GPIO->IF;
|
||||
GPIO->IFC = flag;
|
||||
if (flag & (1<<9))
|
||||
{
|
||||
// printf("pin 9 interrupt\r\n");
|
||||
msgs_to_recv++;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf1(TAG_ERR,"wrong pin int %x\r\n",flag);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void device_init(void)
|
||||
{
|
||||
@@ -107,6 +156,7 @@ void device_init(void)
|
||||
CHIP_Init();
|
||||
enter_DefaultMode_from_RESET();
|
||||
|
||||
// status LEDS
|
||||
GPIO_PinModeSet(gpioPortF,
|
||||
4,
|
||||
gpioModePushPull,
|
||||
@@ -117,7 +167,15 @@ void device_init(void)
|
||||
gpioModePushPull,
|
||||
1);
|
||||
|
||||
// SPI R/W indicator
|
||||
GPIO_PinModeSet(gpioPortC,
|
||||
10,
|
||||
gpioModePushPull,
|
||||
0);
|
||||
|
||||
// USB message rdy ext int
|
||||
GPIO_ExtIntConfig(gpioPortC, 9, 9, 1, 0,1);
|
||||
NVIC_EnableIRQ(GPIO_ODD_IRQn);
|
||||
|
||||
|
||||
printing_init();
|
||||
@@ -127,5 +185,7 @@ void device_init(void)
|
||||
cbor_encoder_init(&test, buf, 20, 0);
|
||||
|
||||
printf("Device init\r\n");
|
||||
int i=0;
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user