ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
30
31#include <stddef.h>
32#include <stdint.h>
33
34#include "ra8_attributes.h"
35#include "ra8_board_ek_ra8d2.h"
37#include "ra8_boot_entry.h"
38#include "ra8_cgc.h"
39#include "ra8_err.h"
40#include "ra8_isr.h"
41#include "ra8_mstp.h"
42#include "ra8_time.h"
43#include "ra8_touch.h"
44
46typedef enum : uint32_t {
47 k_td_uart_baud = 115200U,
49 k_td_poll_max = 20000U,
52
60static const uint8_t s_msg_boot[] = "touch-demo: boot\r\n";
68static const uint8_t s_msg_fail[] = "touch-demo: FAIL init\r\n";
76static const uint8_t s_msg_open[] = "touch: FAIL open\r\n";
84static const uint8_t s_msg_pre[] = "touch: open=OK pts=";
92static const uint8_t s_msg_x[] = " x=";
100static const uint8_t s_msg_y[] = " y=";
108static const uint8_t s_msg_eol[] = "\r\n";
109
122RA8_INTERNAL static void internal_td_print(const uint8_t* msg, uint32_t len)
123{
124 (void)ra8_board_uart_console_write(msg, (size_t)len);
125}
126
140RA8_INTERNAL static void internal_td_panic_halt(const uint8_t* msg, uint32_t len)
141{
142 internal_td_print(msg, len);
143 __asm__ volatile("bkpt #0");
144 while (1) {
145 __asm__ volatile("wfi");
146 }
147}
148
160RA8_INTERNAL static void internal_td_print_uint(uint32_t value)
161{
162 uint8_t buf[k_td_dec_ten];
163 uint32_t n = 0U;
164 if (value == 0U) {
165 buf[n] = '0';
166 n++;
167 }
168 while ((value > 0U) && (n < (uint32_t)k_td_dec_ten)) {
169 buf[n] = (uint8_t)('0' + (value % (uint32_t)k_td_dec_ten));
170 n++;
171 value /= (uint32_t)k_td_dec_ten;
172 }
173 for (uint32_t i = 0U; i < n; i++) {
174 internal_td_print(&buf[n - 1U - i], 1U);
175 }
176}
177
198RA8_INTERNAL static uint8_t internal_td_poll_points(uint16_t* out_x, uint16_t* out_y)
199{
201 uint8_t seen = 0U;
202 *out_x = 0U;
203 *out_y = 0U;
204 for (uint32_t i = 0U; (i < (uint32_t)k_td_poll_max) && (seen == 0U); i++) {
205 uint8_t got = 0U;
206 if ((ra8_touch_read(pts, (uint8_t)k_td_max_points, &got) == k_ra8_ok) && (got >= 1U)) {
207 *out_x = pts[0].x;
208 *out_y = pts[0].y;
209 seen = got;
210 }
211 }
212 return seen;
213}
214
226{
227 uint32_t cpuclk0_hz = 0U;
228 if ((ra8_cgc_init() != k_ra8_ok) || (ra8_mstp_init() != k_ra8_ok)) {
229 internal_td_panic_halt(s_msg_fail, (uint32_t)sizeof(s_msg_fail) - 1U);
230 }
232 internal_td_panic_halt(s_msg_fail, (uint32_t)sizeof(s_msg_fail) - 1U);
233 }
234 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
235 internal_td_panic_halt(s_msg_fail, (uint32_t)sizeof(s_msg_fail) - 1U);
236 }
238 internal_td_panic_halt(s_msg_fail, (uint32_t)sizeof(s_msg_fail) - 1U);
239 }
240}
241
250void main(void)
251{
254 internal_td_print(s_msg_boot, (uint32_t)sizeof(s_msg_boot) - 1U);
255
256 /* The board owns the GT911's channel, address and bus rate, and solves the
257 * bit-rate divider against the live PCLKA. A future board revision that
258 * moves the controller elsewhere changes ra8_board_touch_open, not this. */
259 const ra8_board_touch_cfg_t cfg = {.max_points = (uint8_t)k_td_max_points,
260 .irq_pin = (uint8_t)k_ra8_touch_irq_pin_unset};
261 if (ra8_board_touch_open(&cfg) != k_ra8_ok) {
262 internal_td_panic_halt(s_msg_open, (uint32_t)sizeof(s_msg_open) - 1U);
263 }
264
265 uint16_t px = 0U;
266 uint16_t py = 0U;
267 const uint8_t seen = internal_td_poll_points(&px, &py);
268
269 internal_td_print(s_msg_pre, (uint32_t)sizeof(s_msg_pre) - 1U);
270 internal_td_print_uint((uint32_t)seen);
271 internal_td_print(s_msg_x, (uint32_t)sizeof(s_msg_x) - 1U);
272 internal_td_print_uint((uint32_t)px);
273 internal_td_print(s_msg_y, (uint32_t)sizeof(s_msg_y) - 1U);
274 internal_td_print_uint((uint32_t)py);
275 internal_td_print(s_msg_eol, (uint32_t)sizeof(s_msg_eol) - 1U);
276
277 while (1) {
278 __asm__ volatile("wfi");
279 }
280}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static const uint8_t s_msg_boot[]
Console marker emitted after core and peripheral setup.
Definition main.c:216
static const uint8_t s_msg_fail[]
Diagnostic emitted when the VFS round-trip fails.
Definition main.c:104
static const uint8_t s_msg_pre[]
Prefix for the original page-count diagnostic.
Definition main.c:119
static const uint8_t s_msg_eol[]
Console line terminator for the result banner.
Definition main.c:143
static uint8_t internal_td_poll_points(uint16_t *out_x, uint16_t *out_y)
Poll the GT911 for one touch frame; report the first contact.
Definition main.c:198
static void internal_td_setup_or_halt(void)
Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
Definition main.c:225
static void internal_td_panic_halt(const uint8_t *msg, uint32_t len)
Print the fail banner and trap (ra8_emulator halts on the BKPT).
Definition main.c:140
static const uint8_t s_msg_x[]
Label introducing the first contact X coordinate.
Definition main.c:92
static void internal_td_print_uint(uint32_t value)
Print a small unsigned integer in decimal.
Definition main.c:160
static const uint8_t s_msg_y[]
Label introducing the first contact Y coordinate.
Definition main.c:100
td_consts_t
Console / GT911 / poll knobs (no magic numbers).
Definition main.c:46
@ k_td_poll_max
Bounded poll iterations (NASA R2).
Definition main.c:49
@ k_td_max_points
Read up to the GT911 capacity.
Definition main.c:48
@ k_td_dec_ten
Decimal radix / small-buf cap.
Definition main.c:50
@ k_td_uart_baud
Console baud.
Definition main.c:47
static void internal_td_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the SCI8 console.
Definition main.c:122
static const uint8_t s_msg_open[]
Fatal touch-controller open-failure banner.
Definition main.c:76
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
One-call bring-up of the EK-RA8D2 panel's GoodIX GT911 touch controller.
ra8_err_t ra8_board_touch_open(const ra8_board_touch_cfg_t *cfg)
Bring the on-board GT911 up and open the touch driver against it.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
Multi-touch input driver – GoodIX GT911 backend.
ra8_err_t ra8_touch_read(ra8_touch_point_t *out_points, uint8_t max_count, uint8_t *got_count)
Drain the current touch frame.
Definition ra8_touch.c:551
@ k_ra8_touch_irq_pin_unset
Sentinel for "no IRQ pin attached".
Definition ra8_touch.h:72
The two touch settings that are an APPLICATION choice, not a board fact.
One decoded touch contact.
Definition ra8_touch.h:93
uint16_t x
Panel X coordinate.
Definition ra8_touch.h:94
uint16_t y
Panel Y coordinate.
Definition ra8_touch.h:95