summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-04-20 00:27:35 +0700
committerhathach <[email protected]>2020-04-20 00:27:35 +0700
commite4570c35f757a6fcf7b4998ecd29663627051168 (patch)
tree0f16f62faef0396da20fab7290f04076349cab56
parentf9262007ac41c9fd78e81f27b3477d606a900437 (diff)
add uart for ea4357
-rw-r--r--hw/bsp/ea4357/ea4357.c51
-rw-r--r--src/common/tusb_common.h4
2 files changed, 25 insertions, 30 deletions
diff --git a/hw/bsp/ea4357/ea4357.c b/hw/bsp/ea4357/ea4357.c
index 87f1e83cc..b7e7f7a5c 100644
--- a/hw/bsp/ea4357/ea4357.c
+++ b/hw/bsp/ea4357/ea4357.c
@@ -28,15 +28,14 @@
#include "../board.h"
#include "pca9532.h"
-#define BOARD_UART_PORT LPC_USART0
-#define BOARD_UART_PIN_PORT 0x0f
-#define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD
-#define BOARD_UART_PIN_RX 11 // PF.11 : UART0_RXD
+#define UART_DEV LPC_USART0
+#define UART_PORT 0x0f
+#define UART_PIN_TX 10 // PF.10 : UART0_TXD
+#define UART_PIN_RX 11 // PF.11 : UART0_RXD
// P9_1 joystick down
-#define BUTTON_PORT 4
-#define BUTTON_PIN 13
-
+#define BUTTON_PORT 4
+#define BUTTON_PIN 13
//static const struct {
// uint8_t mux_port;
@@ -68,14 +67,6 @@ static const PINMUX_GRP_T pinmuxing[] =
{0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)},
// USB
-
- /* I2S */
- {0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC2)}, //I2S0_TX_CLK
- {0xC, 12, (SCU_PINIO_FAST | SCU_MODE_FUNC6)}, //I2S0_TX_SDA
- {0xC, 13, (SCU_PINIO_FAST | SCU_MODE_FUNC6)}, //I2S0_TX_WS
- {0x6, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4)}, //I2S0_RX_SCK
- {0x6, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, //I2S0_RX_WS
- {0x6, 2, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, //I2S0_RX_SDA
};
/* Pin clock mux values, re-used structure, value in first index is meaningless */
@@ -127,19 +118,14 @@ void board_init(void)
// Button
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN);
-#if 0
//------------- UART -------------//
- scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1);
- scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1);
+ Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_TX, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC1));
+ Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_RX, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1));
- UART_CFG_Type UARTConfigStruct;
- UART_ConfigStructInit(&UARTConfigStruct);
- UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE;
- UARTConfigStruct.Clock_Speed = 0;
-
- UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
- UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
-#endif
+ Chip_UART_Init(UART_DEV);
+ Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE);
+ Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
+ Chip_UART_TXEnable(UART_DEV);
//------------- USB -------------//
enum {
@@ -278,16 +264,21 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
- //return UART_ReceiveByte(BOARD_UART_PORT);
+ //return UART_ReceiveByte(BOARD_UART_DEV);
(void) buf; (void) len;
return 0;
}
int board_uart_write(void const * buf, int len)
{
- //UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
- (void) buf; (void) len;
- return 0;
+ uint8_t const* buf8 = (uint8_t const*) buf;
+ for(int i=0; i<len; i++)
+ {
+ while ((Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) == 0) {}
+ Chip_UART_SendByte(UART_DEV, buf8[i]);
+ }
+
+ return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index ef232a593..2d80f8210 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -223,12 +223,16 @@ void tu_print_mem(void const *buf, uint16_t count, uint8_t indent);
#define TU_LOG1 tu_printf
#define TU_LOG1_MEM tu_print_mem
#define TU_LOG1_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
+#define TU_LOG1_INT(x) tu_printf(#x " = %ld\n", (uint32_t) (x) )
+#define TU_LOG1_HEX(x) tu_printf(#x " = %lX\n", (uint32_t) (x) )
// Log with debug level 2
#if CFG_TUSB_DEBUG > 1
#define TU_LOG2 TU_LOG1
#define TU_LOG2_MEM TU_LOG1_MEM
#define TU_LOG2_LOCATION() TU_LOG1_LOCATION()
+ #define TU_LOG2_INT TU_LOG1_INT
+ #define TU_LOG2_HEX TU_LOG1_HEX
#endif