ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Standalone GoodIX GT911 capacitive-touch bring-up demo + HIL (#122). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_board_ek_ra8d2_touch.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
#include "ra8_touch.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  td_consts_t : uint32_t {
  k_td_uart_baud = 115200U ,
  k_td_max_points = 5U ,
  k_td_poll_max = 20000U ,
  k_td_dec_ten = 10U
}
 Console / GT911 / poll knobs (no magic numbers). More...

Functions

static void internal_td_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
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).
static void internal_td_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
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.
static void internal_td_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
void main (void)
 App entry: bring up the GT911, poll a touch frame, print the banner.

Variables

static const uint8_t s_msg_boot [] = "touch-demo: boot\r\n"
 Startup banner after console initialization.
static const uint8_t s_msg_fail [] = "touch-demo: FAIL init\r\n"
 Fatal clock, timebase, module, or console setup banner.
static const uint8_t s_msg_open [] = "touch: FAIL open\r\n"
 Fatal touch-controller open-failure banner.
static const uint8_t s_msg_pre [] = "touch: open=OK pts="
 Prefix for the successful open and bounded-poll report.
static const uint8_t s_msg_x [] = " x="
 Label introducing the first contact X coordinate.
static const uint8_t s_msg_y [] = " y="
 Label introducing the first contact Y coordinate.
static const uint8_t s_msg_eol [] = "\r\n"
 CRLF terminator for the composed poll report.

Detailed Description

Standalone GoodIX GT911 capacitive-touch bring-up demo + HIL (#122).

ra8_touch (GT911 over IIC_B channel 0) was only ever exercised inside ereader_ui – there was no standalone example and no CI gate for the touch driver itself. This app is that gate: it brings up the GT911 end-to-end (I2C probe + product-id wake), then polls for a touch frame and reports the first decoded contact on the SCI8 J-Link OB console:

touch: open=OK pts=1 x=<X> y=<Y>

The bring-up half (open=OK) is the deterministic, finger-free part of the gate – it proves the real ra8_touch_open -> IIC_B -> GT911 path reached the product-id check. The point half is exercised under ra8_emulator, which models the GT911 on the modelled I2C bus and injects a tap via --click X Y; that tap returns through the genuine ra8_touch_read decode, so the banner carries a real decoded coordinate. On a bare bench with no finger the poll loop times out and reports pts=0, but open=OK still holds – so hil.conf asserts only the bring-up substring, which is stable either way.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ td_consts_t

enum td_consts_t : uint32_t

Console / GT911 / poll knobs (no magic numbers).

Enumerator
k_td_uart_baud 

Console baud.

k_td_max_points 

Read up to the GT911 capacity.

k_td_poll_max 

Bounded poll iterations (NASA R2).

k_td_dec_ten 

Decimal radix / small-buf cap.

Definition at line 46 of file main.c.

Function Documentation

◆ internal_td_panic_halt()

void internal_td_panic_halt ( const uint8_t * msg,
uint32_t len )
static

Print the fail banner and trap (ra8_emulator halts on the BKPT).

Emits the diagnostic once, executes a debugger-visible breakpoint, then enters a permanent low-power wait loop.

Parameters
[in]msgStart of the failure banner.
[in]lenNumber of banner bytes to transmit.
Precondition
msg addresses at least len readable bytes.
Console setup progressed far enough to accept diagnostics.
Postcondition
The banner has been offered to the console.
Control never returns to the caller.
Note
The terminal loop preserves peripheral state for inspection.
Since
0.1.0

Definition at line 140 of file main.c.

References internal_td_print(), and RA8_INTERNAL.

Referenced by internal_td_setup_or_halt(), and main().

◆ internal_td_poll_points()

uint8_t internal_td_poll_points ( uint16_t * out_x,
uint16_t * out_y )
static

Poll the GT911 for one touch frame; report the first contact.

Calls ra8_touch_read up to k_td_poll_max times (statically bounded). ra8_emulator re-arms an injected --click each SysTick chunk until the firmware drains it, so the loop catches the tap within a few chunks; on a bare bench with no finger it exhausts and reports zero points.

Parameters
[out]out_xReceives the first contact's X (0 if none).
[out]out_yReceives the first contact's Y (0 if none).
Returns
Number of points seen in the caught frame (0 or >=1).
Return values
0No usable touch frame arrived within the bounded poll.
Precondition
out_x and out_y are non-NULL writable pointers.
The touch controller has been opened successfully.
Postcondition
Both outputs hold zero when no contact is found.
On success both outputs hold the first decoded contact.
Note
The polling bound prevents an absent operator from hanging the demo.
Since
0.1.0

Definition at line 198 of file main.c.

References k_ra8_ok, k_td_max_points, k_td_poll_max, RA8_INTERNAL, ra8_touch_read(), ra8_touch_point_t::x, and ra8_touch_point_t::y.

Referenced by main().

◆ internal_td_print()

void internal_td_print ( const uint8_t * msg,
uint32_t len )
static

Emit a byte run on the SCI8 console.

Passes caller-owned bytes and their explicit length directly to the board console.

Parameters
[in]msgStart of the byte run to transmit.
[in]lenNumber of bytes to transmit.
Precondition
msg addresses at least len readable bytes.
The board console is initialized when len is nonzero.
Postcondition
The console has been offered the complete byte run.
No touch-controller state is modified.
Note
Transport status is intentionally ignored by this diagnostic demo.
Since
0.1.0

Definition at line 122 of file main.c.

References ra8_board_uart_console_write(), and RA8_INTERNAL.

Referenced by internal_td_panic_halt(), internal_td_print_uint(), and main().

◆ internal_td_print_uint()

void internal_td_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Builds digits in reverse in a fixed local buffer and emits them most-significant first.

Parameters
[in]valueUnsigned value to render in base ten.
Precondition
k_td_dec_ten can hold every supported value's digits.
The board console is initialized.
Postcondition
The decimal representation has been offered to the console.
No global touch state is modified.
Note
Output has no prefix, padding, or line ending.
Since
0.1.0

Definition at line 160 of file main.c.

References internal_td_print(), k_td_dec_ten, and RA8_INTERNAL.

Referenced by main().

◆ internal_td_setup_or_halt()

void internal_td_setup_or_halt ( void )
static

Bring up clocks/MSTP/time + the SCI8 console; halt on failure.

Initializes each prerequisite in dependency order and treats any failure as terminal.

Precondition
Reset startup completed data and BSS initialization.
Board clock registers are in their reset-compatible state.
Postcondition
On return clocks, module-stop control, time, and SCI8 are initialized.
Any failed prerequisite has emitted the setup-failure banner and halted.
Note
Single-shot boot helper; it is not reentrant.
Since
0.1.0

Definition at line 225 of file main.c.

References internal_td_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_ok, k_td_uart_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_mstp_init(), ra8_time_init(), and s_msg_fail.

Referenced by main().

◆ main()

void main ( void )

App entry: bring up the GT911, poll a touch frame, print the banner.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR / FPU / priority grouping.
Postcondition
The open=OK touch banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 250 of file main.c.

References internal_td_panic_halt(), internal_td_poll_points(), internal_td_print(), internal_td_print_uint(), internal_td_setup_or_halt(), k_ra8_ok, k_ra8_touch_irq_pin_unset, k_td_max_points, ra8_board_touch_open(), ra8_isr_globals_enable(), s_msg_boot, s_msg_eol, s_msg_open, s_msg_pre, s_msg_x, and s_msg_y.

Variable Documentation

◆ s_msg_boot

const uint8_t s_msg_boot[] = "touch-demo: boot\r\n"
static

Startup banner after console initialization.

Marks the point before I2C and touch-controller bring-up begins.

Note
Immutable bytes written with an explicit compile-time length.
Since
0.1.0

Definition at line 60 of file main.c.

◆ s_msg_eol

const uint8_t s_msg_eol[] = "\r\n"
static

CRLF terminator for the composed poll report.

Completes the human-readable result after both coordinates.

Note
Shared only within this translation unit.
Since
0.1.0

Definition at line 108 of file main.c.

◆ s_msg_fail

const uint8_t s_msg_fail[] = "touch-demo: FAIL init\r\n"
static

Fatal clock, timebase, module, or console setup banner.

Provides the deterministic diagnostic for early boot failure.

Note
Consumed only by the terminal panic path.
Since
0.1.0

Definition at line 68 of file main.c.

◆ s_msg_open

const uint8_t s_msg_open[] = "touch: FAIL open\r\n"
static

Fatal touch-controller open-failure banner.

Distinguishes GT911/bus failure from earlier platform setup failure.

Note
Consumed only by the terminal panic path.
Since
0.1.0

Definition at line 76 of file main.c.

Referenced by main().

◆ s_msg_pre

const uint8_t s_msg_pre[] = "touch: open=OK pts="
static

Prefix for the successful open and bounded-poll report.

Followed by the point count and first decoded coordinates.

Note
Contains no line terminator because the report is composed in pieces.
Since
0.1.0

Definition at line 84 of file main.c.

◆ s_msg_x

const uint8_t s_msg_x[] = " x="
static

Label introducing the first contact X coordinate.

Separates the point count from its horizontal position.

Note
Followed immediately by an unsigned decimal value.
Since
0.1.0

Definition at line 92 of file main.c.

Referenced by main().

◆ s_msg_y

const uint8_t s_msg_y[] = " y="
static

Label introducing the first contact Y coordinate.

Separates the horizontal and vertical positions.

Note
Followed immediately by an unsigned decimal value.
Since
0.1.0

Definition at line 100 of file main.c.

Referenced by main().