diff options
| author | Ha Thach <[email protected]> | 2021-01-21 17:14:02 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-21 17:14:02 +0700 |
| commit | 388abe9d9cc0a7c360fd902e01461a53bb7b3f42 (patch) | |
| tree | 9999ca7826378ca26b84c0d38f942a82424827ea /hw | |
| parent | 7aaccd94d2e11ee2329353b4119526c75279b3ba (diff) | |
| parent | 755d4180c957579913380f01c2ec5a77c1738721 (diff) | |
Merge pull request #598 from hathach/pico
RP2040 support
Diffstat (limited to 'hw')
| -rw-r--r-- | hw/bsp/board.h | 7 | ||||
| -rw-r--r-- | hw/bsp/board_mcu.h | 3 | ||||
| -rw-r--r-- | hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c | 99 |
3 files changed, 109 insertions, 0 deletions
diff --git a/hw/bsp/board.h b/hw/bsp/board.h index a8f973a7f..97c80e7c7 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -80,6 +80,13 @@ int board_uart_write(void const * buf, int len); return os_time_ticks_to_ms32( os_time_get() ); } +#elif CFG_TUSB_OS == OPT_OS_PICO +#include "pico/time.h" +static inline uint32_t board_millis(void) + { + return to_ms_since_boot(get_absolute_time()); + } + #else #error "board_millis() is not implemented for this OS" #endif diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h index 1cf0ad03c..a175197e5 100644 --- a/hw/bsp/board_mcu.h +++ b/hw/bsp/board_mcu.h @@ -117,6 +117,9 @@ #elif CFG_TUSB_MCU == OPT_MCU_DA1469X #include "DA1469xAB.h" +#elif CFG_TUSB_MCU == OPT_MCU_RP2040 + #include "pico.h" + #else #error "Missing MCU header" #endif diff --git a/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c b/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c new file mode 100644 index 000000000..efdb54733 --- /dev/null +++ b/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c @@ -0,0 +1,99 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include "pico/stdlib.h" +#include "../board.h" + +#ifndef LED_PIN +#define LED_PIN PICO_DEFAULT_LED_PIN +#endif + +void board_init(void) +{ + setup_default_uart(); + gpio_init(LED_PIN); + gpio_set_dir(LED_PIN, 1); + + // Button + + // todo probably set up device mode? + +#if TUSB_OPT_HOST_ENABLED + // set portfunc to host !!! +#endif +} + +////--------------------------------------------------------------------+ +//// USB Interrupt Handler +////--------------------------------------------------------------------+ +//void USB_IRQHandler(void) +//{ +//#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST +// tuh_isr(0); +//#endif +// +//#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE +// tud_int_handler(0); +//#endif +//} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +void board_led_write(bool state) +{ + gpio_put(LED_PIN, state); +} + +uint32_t board_button_read(void) +{ + return 0; +} + +int board_uart_read(uint8_t* buf, int len) +{ + for(int i=0;i<len;i++) { + buf[i] = uart_getc(uart_default); + } + return 0; +} + +int board_uart_write(void const * buf, int len) +{ +// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); + for(int i=0;i<len;i++) { + uart_putc(uart_default, ((char *)buf)[i]); + } + return 0; +} + +#if CFG_TUSB_OS == OPT_OS_NONE +uint32_t board_millis(void) +{ + return to_ms_since_boot(get_absolute_time()); +} +#endif |
