ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_riic_devices.c
Go to the documentation of this file.
1
12
15
24
30typedef struct {
31 uint8_t reg_ptr;
32 bool ptr_set;
34 uint32_t writes;
36
49
56typedef struct {
57 uint16_t reg_ptr;
58 uint8_t ptr_bytes;
59 uint8_t reg_format;
60 uint8_t reg_isp_mux;
61 uint8_t reg_test;
62 uint32_t writes;
63 uint32_t id_reads;
65
70
84{
85 for (uint32_t i = 0U; i < (uint32_t)k_riic_dev_max; i++) {
86 if (!s_riic_dev[i].present) {
87 s_riic_dev[i] = device;
88 return;
89 }
90 }
91}
92
106RA8_INTERNAL static void internal_pi4ioe_write(void* ctx, uint8_t byte)
107{
109 if (!p->ptr_set) {
110 p->reg_ptr = (uint8_t)(byte % (uint8_t)k_pi4ioe_reg_max);
111 p->ptr_set = true;
112 return;
113 }
114 p->file[p->reg_ptr] = byte;
115 p->reg_ptr = (uint8_t)((p->reg_ptr + 1U) % (uint8_t)k_pi4ioe_reg_max);
116 p->writes++;
117}
118
136RA8_INTERNAL static uint32_t internal_pi4ioe_read(void* ctx, uint8_t* buf, uint32_t max)
137{
139 if (max == 0U) {
140 return 0U;
141 }
142 const uint32_t n = (max < (uint32_t)k_pi4ioe_reg_max) ? max : (uint32_t)k_pi4ioe_reg_max;
143 for (uint32_t i = 0U; i < n; i++) {
144 const uint8_t reg = (uint8_t)((p->reg_ptr + i) % (uint8_t)k_pi4ioe_reg_max);
145 buf[i] = p->file[reg];
146 }
147 return n;
148}
149
162RA8_INTERNAL static void internal_pi4ioe_stop(void* ctx)
163{
164 ((pi4ioe_state_t*)ctx)->ptr_set = false;
165}
166
180RA8_INTERNAL static void internal_ov5640_write(void* ctx, uint8_t byte)
181{
182 ov5640_state_t* sensor = (ov5640_state_t*)ctx;
183 if (sensor->ptr_bytes < (uint8_t)k_ov5640_ptr_bytes) {
184 if (sensor->ptr_bytes == 0U) {
185 sensor->reg_ptr = 0U;
186 }
187 sensor->reg_ptr = (uint16_t)(((uint16_t)(sensor->reg_ptr << 8U)) | (uint16_t)byte);
188 sensor->ptr_bytes++;
189 return;
190 }
191 if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_format) {
192 sensor->reg_format = byte;
193 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_isp_mux) {
194 sensor->reg_isp_mux = byte;
195 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_test) {
196 sensor->reg_test = byte;
197 }
198 sensor->writes++;
199}
200
217RA8_INTERNAL static uint32_t internal_ov5640_read(void* ctx, uint8_t* buf, uint32_t max)
218{
219 ov5640_state_t* sensor = (ov5640_state_t*)ctx;
220 if (max == 0U) {
221 return 0U;
222 }
223 uint8_t value = 0U;
224 if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_id_hi) {
225 value = (uint8_t)k_ov5640_id_hi;
226 sensor->id_reads++;
227 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_id_lo) {
228 value = (uint8_t)k_ov5640_id_lo;
229 sensor->id_reads++;
230 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_format) {
231 value = sensor->reg_format;
232 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_isp_mux) {
233 value = sensor->reg_isp_mux;
234 } else if (sensor->reg_ptr == (uint16_t)k_ov5640_reg_test) {
235 value = sensor->reg_test;
236 }
237 buf[0] = value;
238 return 1U;
239}
240
253RA8_INTERNAL static void internal_ov5640_stop(void* ctx)
254{
255 ((ov5640_state_t*)ctx)->ptr_bytes = 0U;
256}
257
259{
260 for (uint32_t i = 0U; i < (uint32_t)k_riic_dev_max; i++) {
261 if (s_riic_dev[i].present && (s_riic_dev[i].addr_7b == addr_7b)) {
262 return &s_riic_dev[i];
263 }
264 }
265 return nullptr;
266}
267
269{
270 for (uint32_t i = 0U; i < (uint32_t)k_riic_dev_max; i++) {
271 s_riic_dev[i] = (riic_device_t){};
272 }
276 .addr_7b = (uint8_t)k_pi4ioe_addr_7b,
278 .read = internal_pi4ioe_read,
279 .stop = internal_pi4ioe_stop,
280 .ctx = &s_pi4ioe});
281
284 .addr_7b = (uint8_t)k_ov5640_addr_7b,
286 .read = internal_ov5640_read,
287 .stop = internal_ov5640_stop,
288 .ctx = &s_ov5640});
289}
290
292{
293 if (s_pi4ioe.writes > 0U) {
294 (void)priv_emu_io_errf(" RIIC PI4IOE : U15 expander 0x%02X acked %u register write(s)\n",
295 (unsigned)k_pi4ioe_addr_7b,
296 s_pi4ioe.writes);
297 }
298 if ((s_ov5640.id_reads > 0U) || (s_ov5640.writes > 0U)) {
299 (void)priv_emu_io_errf(
300 " RIIC OV5640 : SCCB 0x%02X chip-id 0x5640 (%u id read(s), %u cfg write(s))\n",
301 (unsigned)k_ov5640_addr_7b,
302 s_ov5640.id_reads,
303 s_ov5640.writes);
304 }
305}
riic_device_const_t
Registry and PI4IOE5V6408 geometry.
@ k_pi4ioe_reg_max
Register-file size modelled (0x00..0x0F).
@ k_riic_dev_max
Device-registry capacity.
@ k_pi4ioe_reg_devid
Device-id register.
@ k_pi4ioe_devid_val
Device-id reset default.
@ k_pi4ioe_addr_7b
EK-RA8D2 U15 default 7-bit address.
static RA8_INTERNAL uint32_t internal_pi4ioe_read(void *ctx, uint8_t *buf, uint32_t max)
Serve PI4IOE5V6408 register bytes to the controller.
RA8_PRIV void priv_riic_devices_reset(void)
Reset and repopulate the board's RIIC device registry.
static RA8_INTERNAL uint32_t internal_ov5640_read(void *ctx, uint8_t *buf, uint32_t max)
Serve one verifier-visible OV5640 register byte.
static pi4ioe_state_t s_pi4ioe
static ov5640_state_t s_ov5640
static RA8_INTERNAL void internal_pi4ioe_write(void *ctx, uint8_t byte)
Accept one controller byte for the PI4IOE5V6408.
static RA8_INTERNAL void internal_ov5640_write(void *ctx, uint8_t byte)
Accept pointer and configuration bytes for the OV5640.
ov5640_const_t
OV5640 SCCB sensor constants used by camera_capture.
@ k_ov5640_addr_7b
SCCB 7-bit address.
@ k_ov5640_id_hi
Chip-ID high byte.
@ k_ov5640_reg_id_lo
Chip-ID low-byte register.
@ k_ov5640_ptr_bytes
Big-endian register-pointer byte count.
@ k_ov5640_reg_id_hi
Chip-ID high-byte register.
@ k_ov5640_id_lo
Chip-ID low byte.
RA8_PRIV void priv_riic_devices_report(void)
Report activity observed by the registered board devices.
static RA8_INTERNAL void internal_pi4ioe_stop(void *ctx)
End a PI4IOE5V6408 transfer.
static RA8_INTERNAL void internal_ov5640_stop(void *ctx)
End an OV5640 SCCB transfer.
static RA8_INTERNAL void internal_riic_device_register(riic_device_t device)
Register one device in the first free bus slot.
static riic_device_t s_riic_dev[k_riic_dev_max]
Fixed registry and board-device states.
RA8_PRIV riic_device_t * priv_riic_device_find(uint8_t addr_7b)
Find the registered RIIC device answering one 7-bit address.
Internal RIIC bus-device registry and board-device models.
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
-proof
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ov5640_reg_format
DVP output pixel format register.
Definition ra8_ov5640.c:60
@ k_ov5640_reg_test
Pre-output test-pattern register.
Definition ra8_ov5640.c:84
@ k_ov5640_reg_isp_mux
ISP output format-mux register.
Definition ra8_ov5640.c:83
One OV5640 camera sensor on the SCCB bus.
uint8_t ptr_bytes
Pointer bytes captured this transfer.
uint8_t reg_isp_mux
Latched 0x501F ISP output mux.
uint8_t reg_format
Latched 0x4300 DVP output format.
uint32_t writes
Config register writes accepted.
uint32_t id_reads
Chip-ID bytes served for reporting.
uint8_t reg_test
Latched 0x503D test-pattern control.
uint16_t reg_ptr
Active 16-bit register pointer.
One PI4IOE5V6408 I/O expander on the modelled I2C bus.
uint8_t file[k_pi4ioe_reg_max]
Register-file shadow.
uint32_t writes
Register writes the controller landed.
uint8_t reg_ptr
Active auto-incrementing register pointer.
bool ptr_set
First byte of this transfer set the ptr.
One device registered on the modelled RIIC bus.