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_lpcxpresso1347.c
1 /**************************************************************************/
37 /**************************************************************************/
38 
39 #include "../board.h"
40 
41 #if BOARD == BOARD_LPCXPRESSO1347
42 
43 #define LED_PORT (0)
44 #define LED_PIN (7)
45 #define LED_ON (1)
46 #define LED_OFF (0)
47 
48 const static struct {
49  uint8_t port;
50  uint8_t pin;
51 } buttons[] =
52 {
53  {1, 22 }, // Joystick up
54  {1, 20 }, // Joystick down
55  {1, 23 }, // Joystick left
56  {1, 21 }, // Joystick right
57  {1, 19 }, // Joystick press
58  {0, 1 }, // SW3
59 // {1, 4 }, // SW4 (require to remove J28)
60 };
61 
62 enum {
63  BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
64 };
65 
66 
67 void board_init(void)
68 {
69  SystemInit();
70 
71 #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
72  SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
73 #endif
74 
75  GPIOInit();
76 
77  //------------- LED -------------//
78  GPIOSetDir(LED_PORT, LED_PIN, 1);
79 
80  //------------- BUTTON -------------//
81  for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, BIT_(buttons[i].pin), 0);
82 
83  //------------- UART -------------//
84  UARTInit(CFG_UART_BAUDRATE);
85 
86 }
87 
88 //--------------------------------------------------------------------+
89 // LEDS
90 //--------------------------------------------------------------------+
91 void board_leds(uint32_t on_mask, uint32_t off_mask)
92 {
93  if (on_mask & BIT_(0))
94  {
95  GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON);
96  }else if (off_mask & BIT_(0))
97  {
98  GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF);
99  }
100 }
101 
102 //--------------------------------------------------------------------+
103 // BUTTONS
104 //--------------------------------------------------------------------+
105 static bool button_read(uint8_t id)
106 {
107  return !GPIOGetPinValue(buttons[id].port, buttons[id].pin); // button is active low
108 }
109 
110 uint32_t board_buttons(void)
111 {
112  uint32_t result = 0;
113 
114  for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
115 
116  return result;
117 }
118 
119 //--------------------------------------------------------------------+
120 // UART
121 //--------------------------------------------------------------------+
122 void board_uart_putchar(uint8_t c)
123 {
124  UARTSend(&c, 1);
125 }
126 
127 uint8_t board_uart_getchar(void)
128 {
129  return 0;
130 }
131 
132 #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