|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2019, hathach (tinyusb.org) |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +#include "../board.h" |
| 27 | + |
| 28 | +#include "sam.h" |
| 29 | + |
| 30 | +#include <stdint.h> |
| 31 | +#include <stdbool.h> |
| 32 | + |
| 33 | +#define CONF_CPU_FREQUENCY 96000000 |
| 34 | + |
| 35 | +//--------------------------------------------------------------------+ |
| 36 | +// MACRO TYPEDEF CONSTANT ENUM DECLARATION |
| 37 | +//--------------------------------------------------------------------+ |
| 38 | + |
| 39 | +//------------- IMPLEMENTATION -------------// |
| 40 | +void board_init(void) |
| 41 | +{ |
| 42 | + init_mcu(); |
| 43 | + |
| 44 | + /* Disable Watchdog */ |
| 45 | + WDT->WDT_MR |= WDT_MR_WDDIS; |
| 46 | + |
| 47 | + // LED |
| 48 | +// _pmc_enable_periph_clock(ID_PIOC); |
| 49 | +// gpio_set_pin_level(LED_PIN, false); |
| 50 | +// gpio_set_pin_direction(LED_PIN, GPIO_DIRECTION_OUT); |
| 51 | +// gpio_set_pin_function(LED_PIN, GPIO_PIN_FUNCTION_OFF); |
| 52 | + |
| 53 | + // Button |
| 54 | +// _pmc_enable_periph_clock(ID_PIOA); |
| 55 | +// gpio_set_pin_direction(BUTTON_PIN, GPIO_DIRECTION_IN); |
| 56 | +// gpio_set_pin_pull_mode(BUTTON_PIN, GPIO_PULL_UP); |
| 57 | +// gpio_set_pin_function(BUTTON_PIN, GPIO_PIN_FUNCTION_OFF); |
| 58 | + |
| 59 | + // Uart via EDBG Com |
| 60 | +// _pmc_enable_periph_clock(ID_USART1); |
| 61 | +// gpio_set_pin_function(UART_RX_PIN, MUX_PA21A_USART1_RXD1); |
| 62 | +// gpio_set_pin_function(UART_TX_PIN, MUX_PB4D_USART1_TXD1); |
| 63 | + |
| 64 | +// usart_async_init(&edbg_com, USART1, edbg_com_buffer, sizeof(edbg_com_buffer), _usart_get_usart_async()); |
| 65 | +// usart_async_set_baud_rate(&edbg_com, CFG_BOARD_UART_BAUDRATE); |
| 66 | +// usart_async_register_callback(&edbg_com, USART_ASYNC_TXC_CB, tx_cb_EDBG_COM); |
| 67 | +// usart_async_enable(&edbg_com); |
| 68 | + |
| 69 | +#if CFG_TUSB_OS == OPT_OS_NONE |
| 70 | + // 1ms tick timer (samd SystemCoreClock may not correct) |
| 71 | + SysTick_Config(CONF_CPU_FREQUENCY / 1000); |
| 72 | +#endif |
| 73 | + |
| 74 | + // Enable USB clock |
| 75 | +// _pmc_enable_periph_clock(ID_UDPHS); |
| 76 | +} |
| 77 | + |
| 78 | +//--------------------------------------------------------------------+ |
| 79 | +// USB Interrupt Handler |
| 80 | +//--------------------------------------------------------------------+ |
| 81 | +void USBHS_Handler(void) |
| 82 | +{ |
| 83 | + tud_int_handler(0); |
| 84 | +} |
| 85 | + |
| 86 | +//--------------------------------------------------------------------+ |
| 87 | +// Board porting API |
| 88 | +//--------------------------------------------------------------------+ |
| 89 | + |
| 90 | +void board_led_write(bool state) |
| 91 | +{ |
| 92 | + (void) state; |
| 93 | +// gpio_set_pin_level(LED_PIN, state); |
| 94 | +} |
| 95 | + |
| 96 | +uint32_t board_button_read(void) |
| 97 | +{ |
| 98 | + return 0; |
| 99 | +// return BUTTON_STATE_ACTIVE == gpio_get_pin_level(BUTTON_PIN); |
| 100 | +} |
| 101 | + |
| 102 | +int board_uart_read(uint8_t* buf, int len) |
| 103 | +{ |
| 104 | + (void) buf; (void) len; |
| 105 | + return 0; |
| 106 | +} |
| 107 | + |
| 108 | +int board_uart_write(void const * buf, int len) |
| 109 | +{ |
| 110 | + (void) buf; (void) len; |
| 111 | + // while until previous transfer is complete |
| 112 | +// while(uart_busy) {} |
| 113 | +// uart_busy = true; |
| 114 | + |
| 115 | +// io_write(&edbg_com.io, buf, len); |
| 116 | + return len; |
| 117 | +} |
| 118 | + |
| 119 | +#if CFG_TUSB_OS == OPT_OS_NONE |
| 120 | +volatile uint32_t system_ticks = 0; |
| 121 | + |
| 122 | +void SysTick_Handler(void) |
| 123 | +{ |
| 124 | + system_ticks++; |
| 125 | +} |
| 126 | + |
| 127 | +uint32_t board_millis(void) |
| 128 | +{ |
| 129 | + return system_ticks; |
| 130 | +} |
| 131 | +#endif |
| 132 | + |
| 133 | +// Required by __libc_init_array in startup code if we are compiling using |
| 134 | +// -nostdlib/-nostartfiles. |
| 135 | +void _init(void) |
| 136 | +{ |
| 137 | + |
| 138 | +} |
0 commit comments