tinyusb  0.4
Click here to lend your support to tinyusb donation and make a donation at pledgie.com
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
board_mcb4300.c
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
39 #include "../board.h"
40 
41 #if BOARD == BOARD_MCB4300
42 
43 //--------------------------------------------------------------------+
44 // INCLUDE
45 //--------------------------------------------------------------------+
46 #define BOARD_MAX_LEDS 8
47 
48 #define BOARD_UART_PORT LPC_USART0
49 #define BOARD_UART_PIN_PORT 2
50 #define BOARD_UART_PIN_TX 0
51 #define BOARD_UART_PIN_RX 1
52 
53 //--------------------------------------------------------------------+
54 // MACRO CONSTANT TYPEDEF
55 //--------------------------------------------------------------------+
56 static const uint8_t ledports[] = {6, 6, 6, 6, 6, 4, 4, 4};
57 static const uint8_t ledbits[] = {24, 25, 26, 27, 28, 12, 13, 14};
58 
59 const static struct {
60  uint8_t port;
61  uint8_t pin;
62 }leds[BOARD_MAX_LEDS] = {
63  {6, 24}, {6, 25}, {6, 26}, {6, 27},
64  {4, 28}, {4, 12}, {4, 13}, {4, 14}};
65 
66 //--------------------------------------------------------------------+
67 // INTERNAL OBJECT & FUNCTION DECLARATION
68 //--------------------------------------------------------------------+
69 
70 //--------------------------------------------------------------------+
71 // IMPLEMENTATION
72 //--------------------------------------------------------------------+
73 void board_init(void)
74 {
75  CGU_Init();
76 
77 #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
78  SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
79 #endif
80 
81  //------------- USB Bus power HOST ONLY-------------//
82  // Keil VBUS0 is P6_3
83  scu_pinmux(0x6, 3, MD_PUP | MD_EZI, FUNC1); // P6_3 USB0_PWR_EN, USB0 VBus function
84 
85  // Keil VBUS1 is P9_5
86  scu_pinmux(0x9, 5, MD_PUP | MD_EZI, FUNC2); // P9_5 USB1_PWR_EN, USB1 VBus function
87 
88  //------------- LEDs init, J21 must be installed -------------//
89  LPC_SCU->SFSPD_10 = 4; // GPIO6[24]
90  LPC_SCU->SFSPD_11 = 4; // GPIO6[25]
91  LPC_SCU->SFSPD_12 = 4; // GPIO6[26]
92  LPC_SCU->SFSPD_13 = 4; // GPIO6[27]
93  LPC_SCU->SFSPD_14 = 4; // GPIO6[28]
94  LPC_SCU->SFSP9_0 = 0; // GPIO4[12]
95  LPC_SCU->SFSP9_1 = 0; // GPIO4[13]
96  LPC_SCU->SFSP9_2 = 0; // GPIO4[14]
97 
98  for(uint32_t i=0; i<BOARD_MAX_LEDS; i++)
99  {
100  GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output
101  }
102 
103  //------------- UART -------------//
104  scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN , FUNC1);
105  scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN|MD_EZI|MD_ZI, FUNC1);
106 
107  UART_CFG_Type UARTConfigStruct;
108  UART_ConfigStructInit(&UARTConfigStruct);
109  UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
110  UARTConfigStruct.Clock_Speed = 0;
111 
112  UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
113  UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
114 }
115 
116 //--------------------------------------------------------------------+
117 // LEDS
118 //--------------------------------------------------------------------+
119 void board_leds(uint32_t on_mask, uint32_t off_mask)
120 {
121  for (uint32_t i=0; i<BOARD_MAX_LEDS; i++)
122  {
123  if ( on_mask & BIT_(i))
124  {
125  GPIO_SetValue(leds[i].port, BIT_(leds[i].pin));
126  }else if ( off_mask & BIT_(i)) // on_mask take precedence over off_mask
127  {
128  GPIO_ClearValue(leds[i].port, BIT_(leds[i].pin));
129  }
130  }
131 }
132 
133 //--------------------------------------------------------------------+
134 // BUTTONS
135 //--------------------------------------------------------------------+
136 uint32_t board_buttons(void)
137 {
138  return 0; // TODO buttons for mcb4300
139 }
140 
141 //--------------------------------------------------------------------+
142 // UART
143 //--------------------------------------------------------------------+
144 uint8_t board_uart_getchar(void)
145 {
146  return UART_ReceiveByte(BOARD_UART_PORT);
147 }
148 
149 void board_uart_putchar(uint8_t c)
150 {
151  UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
152 }
153 
154 #endif
#define BIT_(n)
n-th Bit
Definition: binary.h:54
void board_init(void)
Initialize all required peripherals on board including uart, led, buttons etc ... ...
void board_leds(uint32_t on_mask, uint32_t off_mask)
Turns on and off leds on the board.
uint32_t board_buttons(void)
Get the current state of the buttons on the board.
void board_uart_putchar(uint8_t c)
Send a character to UART.
#define TUSB_CFG_TICKS_HZ
The rate ticks in hert. This is used in conjunction with tusb_tick_get to calculate timing...
uint8_t board_uart_getchar(void)
Get a character input from UART.
#define CFG_UART_BAUDRATE
Baudrate for UART.
Definition: board.h:119