blob: 256bccd15d44645c41b5b7c778e8e3dc2ea6253c [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright 2019 Sony Semiconductor Solutions Corporation
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 * This file is part of the TinyUSB stack.
25 */
26
27#include <sys/boardctl.h>
28#include <nuttx/arch.h>
29#include <arch/board/board.h>
30#include <arch/chip/pin.h>
31
32#include "bsp/board.h"
33
34/*------------------------------------------------------------------*/
35/* MACRO TYPEDEF CONSTANT ENUM
36 *------------------------------------------------------------------*/
37#define LED_PIN PIN_I2S1_BCK
38
39#define BUTTON_PIN PIN_HIF_IRQ_OUT
40
41// Initialize on-board peripherals : led, button, uart and USB
42void board_init(void)
43{
44 boardctl(BOARDIOC_INIT, 0);
45
46 board_gpio_write(PIN_I2S1_BCK, -1);
47 board_gpio_config(PIN_I2S1_BCK, 0, false, true, PIN_FLOAT);
48
49 board_gpio_write(PIN_HIF_IRQ_OUT, -1);
50 board_gpio_config(PIN_HIF_IRQ_OUT, 0, true, true, PIN_FLOAT);
51};
52
53//--------------------------------------------------------------------+
54// Board porting API
55//--------------------------------------------------------------------+
56
57// Turn LED on or off
58void board_led_write(bool state)
59{
60 board_gpio_write(LED_PIN, state);
61}
62
63// Get the current state of button
64// a '1' means active (pressed), a '0' means inactive.
65uint32_t board_button_read(void)
66{
67 if (board_gpio_read(BUTTON_PIN))
68 {
69 return 0;
70 }
71
72 return 1;
73}
74
75// Get characters from UART
76int board_uart_read(uint8_t *buf, int len)
77{
78 int r = read(0, buf, len);
79
80 return r;
81}
82
83// Send characters to UART
84int board_uart_write(void const *buf, int len)
85{
86 int r = write(1, buf, len);
87
88 return r;
89}
90
91// Get current milliseconds
92uint32_t board_millis(void)
93{
94 struct timespec tp;
95
96 /* Wait until RTC is available */
97 while (g_rtc_enabled == false);
98
99 if (clock_gettime(CLOCK_MONOTONIC, &tp))
100 {
101 return 0;
102 }
103
104 return (((uint64_t)tp.tv_sec) * 1000 + tp.tv_nsec / 1000000);
105}