RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
cam.c
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
15
16#include "cam/cam.h"
17#include "debug.h"
18
20 // Safety check! Ensure the pointer actually exists before calling it
21 if (cam != NULL && cam->drv != NULL && cam->drv->applyConfig != NULL) {
22
23 return cam->drv->applyConfig(cam);
24 }
25
26 return CAM_ERR;
27}
29
30 if (cam != NULL && cam->drv != NULL && cam->drv->enableErrorInterrupt != NULL) {
31 return cam->drv->enableErrorInterrupt(cam);
32 }
33 return CAM_ERR;
34}
35
36void cam_writeReg(cam_instance_t *cam, u16 reg, u8 data)
37{
38 i2c_instance_t *inst = cam->inst;
39
41
42 i2c_sendTxByte(inst, cam->inst->slaveAddress);
44 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
45
46 i2c_sendTxByte(inst, (reg>>8) & 0xFF);
48 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
49
50 i2c_sendTxByte(inst, (reg) & 0xFF);
52 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
53
54 i2c_sendTxByte(inst, data & 0xFF);
56 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
57
59}
60
62{
63 i2c_instance_t *inst = cam->inst;
64 u8 outdata;
65
67
68 i2c_sendTxByte(inst, cam->inst->slaveAddress);
70 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
71
72 i2c_sendTxByte(inst, (reg>>8) & 0xFF);
74 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
75
76 i2c_sendTxByte(inst, (reg) & 0xFF);
78 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
79
82
83 i2c_sendTxByte(inst, cam->inst->slaveAddress | 0x01);
85 BSP_ASSERT(i2c_getRxAck(inst),"Failed to Assert!\n"); // Optional check
86
87 i2c_sendTxByte(inst, 0xFF);
89 BSP_ASSERT(i2c_getRxNack(inst),"Failed to Assert!\n"); // Optional check
90 outdata = i2c_getRxData(inst);
91
93
94 return outdata;
95}
cam_status_t enableErrorInterrupt(cam_instance_t *cam)
Definition cam.c:28
cam_status_t applyConfig(cam_instance_t *cam)
Definition cam.c:19
CAM driver API definitions.
Debug, logging, and assertion API.
cam_status_t
CAM Status List.
Definition cam.h:90
@ CAM_ERR
Failed to retrieve/write value *‍/.
Definition cam.h:92
void cam_writeReg(cam_instance_t *cam, u16 reg, u8 data)
Write Data to specific register in camera.
Definition cam.c:36
u8 cam_readReg(cam_instance_t *cam, u16 reg)
Read Data from specific register in camera.
Definition cam.c:61
struct cam_instance cam_instance_t
Forward declaration of CAM instance.
Definition cam.h:137
#define BSP_ASSERT(cond, msg)
Assert a condition. Prints message and halts on failure.
Definition debug.h:218
void i2c_startMasterBlocking(i2c_instance_t *inst)
Initiate start condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:113
void i2c_sendNackBlocking(i2c_instance_t *inst)
Sends an NACK signal over the I2C bus and waits until the transmission is complete.
Definition i2c.c:156
void i2c_sendTxByte(i2c_instance_t *inst, u8 byte)
Transmits a byte of data over I2C.
Definition i2c.c:178
u32 i2c_getRxData(i2c_instance_t *inst)
Reads data from I2C receive data register.
Definition i2c.c:58
u32 i2c_getRxNack(i2c_instance_t *inst)
Checks if the received ACK signal is detected.
Definition i2c.c:63
void i2c_stopMasterBlocking(i2c_instance_t *inst)
Initiate stop condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:129
u32 i2c_getRxAck(i2c_instance_t *inst)
Reads Acknowledge signal from I2C receive data register.
Definition i2c.c:68
cam_status_t(* applyConfig)(cam_instance_t *cam)
Apply i2c config.
Definition cam.h:144
cam_status_t(* enableErrorInterrupt)(cam_instance_t *cam)
Enable error interrupt function pointer.
Definition cam.h:145
const cam_api_t * drv
Pointer to CAM API structure *‍/.
Definition cam.h:161
i2c_instance_t * inst
Pointer to I2C instance *‍/.
Definition cam.h:160
I2C instance. Holds the software registers and hardware pointer.
Definition i2c.h:290
u32 slaveAddress
7-bit Slave Address
Definition i2c.h:292
uint8_t u8
Definition type.h:30
uint16_t u16
Definition type.h:28