Sense.CAM.P
Ultra-low-power global-shutter camera driver for Sense.CAM.P (rev a).
Embeds the PixArt PAG7920J3, a 320 x 240 monochrome global-shutter camera module with an integrated lens in a 2.94 x 2.44 x 2.11 mm cube. Registers are configured over I2C; image data comes out over SPI. The tile does not break out the 8-bit parallel bus, so SPI is the only image path.
Examples
Quick start
#include "core_tiles.h"
static uint8_t frame[160 * 120];
tile_t cam;
sense_cam_p_cfg_t cfg = { .spi_cs = 9, .resolution = SENSE_CAM_P_RES_160x120 };
tile_sense_cam_p_init(core_tiles_pal(&core_i2c1), 0, &cam, &cfg);
if (tile_is_ready(&cam))
tile_sense_cam_p_capture(&cam, frame, sizeof(frame));API reference
Initialization
tile_sense_cam_p_find
uint8_t tile_sense_cam_p_find(tiles_pal_t* hal, uint8_t instance)Check whether a PAG7920J3 is present on the I2C bus.
- hal
- Platform HAL handle
- instance
- Instance index (0 = default, see mapping table)
Returns 1 if the device ACKs, 0 otherwise
tile_sense_cam_p_init
void tile_sense_cam_p_init(tiles_pal_t* hal, uint8_t instance, tile_t* tile, const sense_cam_p_cfg_t* cfg)Verifies PartID, applies the vendor init tables verbatim for the requested resolution, then confirms the SPI link by reading CheckID. Pass cfg=NULL for defaults (spi_cs 0, 160x120).
- hal
- Platform HAL handle
- instance
- Instance index (0 = default, see mapping table)
- tile
- Pointer to tile handle (populated by this function)
- cfg
- Optional config, or NULL for defaults
- Blocks for ~250 ms. Requires both an I2C bus and an SPI bus on the PAL. Single-instance: the SPI CS and resolution are driver-global.
Lifecycle
tile_sense_cam_p_part_id
Studiouint16_t tile_sense_cam_p_part_id(tile_t* tile)Read the 16-bit part identifier over I2C.
Returns 0x7920 for a healthy PAG7920J3, 0 on a bus error.
tile_sense_cam_p_spi_id
Studiouint16_t tile_sense_cam_p_spi_id(tile_t* tile)Read the SPI-side identifier, confirming the SPI link is usable.
Returns 0xA55A when the SPI link is up, 0 otherwise.
- Returns 0x0000 whenever the sensor is stopped — the SPI register interface is only alive while R_TG_En = 1.
tile_sense_cam_p_reset
Studiovoid tile_sense_cam_p_reset(tile_t* tile)Preferred over a power cycle for repeatable tests: the tile carries ~15.7 uF of bulk and at the camera's microamp idle draw that rail can take seconds to fall below the power-on-reset threshold, so an unplug/replug may not reset the part at all.
- Leaves the sensor unconfigured; call init again afterwards.
Runtime
tile_sense_cam_p_capture
Studiouint8_t tile_sense_cam_p_capture(tile_t* tile, uint8_t* dst, uint32_t len)Frame-locks on Frame_Start, then reads the frame in 4800-byte buffers. The caller owns the memory: 19200 bytes at 160x120, 76800 at 320x240. Each buffer must be serviced within roughly 3.4 ms at default timing, or FB_Ovf trips and the frame is void. Anything slow between buffers — a per-byte print, a slow link — will tear the image across several exposures.
- dst
- Destination buffer.
- len
- Size of dst; must be >= tile_sense_cam_p_frame_bytes().
Returns 1 on a complete, non-overflowed frame; 0 otherwise.
Config
tile_sense_cam_p_width
Studiouint16_t tile_sense_cam_p_width(tile_t* tile)Frame width in pixels for the configured resolution.
Returns 160 or 320.
tile_sense_cam_p_height
Studiouint16_t tile_sense_cam_p_height(tile_t* tile)Frame height in pixels for the configured resolution.
Returns 120 or 240.
tile_sense_cam_p_frame_bytes
Studiouint32_t tile_sense_cam_p_frame_bytes(tile_t* tile)Number of bytes one frame occupies (width x height, 8-bit RAW).
Returns 19200 or 76800.
Driver gaps · 8
Chip capabilities this driver doesn’t expose yet.
Enums
sense_cam_p_res_t
@brief Capture resolution.
- SENSE_CAM_P_RES_160x120
- 19200 B/frame, analog 2x skip.
- SENSE_CAM_P_RES_320x240
- 76800 B/frame, full array.
Constants
| TILE_SENSE_CAM_P_VERSION_MAJOR | 0 | |
| TILE_SENSE_CAM_P_VERSION_MINOR | 1 | |
| TILE_SENSE_CAM_P_VERSION_PATCH | 0 | |
| PAG7920_I2C_ADDR_FLOAT | 0x35 | GPIO2 floating (tile default). |
| PAG7920_I2C_ADDR_HIGH | 0x25 | GPIO2 tied to VDDIO. |
| PAG7920_I2C_ADDR_GND | 0x40 | GPIO2 tied to GND. |
| PAG7920_I2C_ADDR_BROADCAST | 0x60 | Always live, strap-independent. |
| PAG7920_PART_ID | 0x7920 | Expected PartID. |
| PAG7920_SPI_RD_BIT | 0x80 | Bit 7 of byte 0: 1 = read. Addr is 7-bit. |
| PAG7920_SPI_IMG_RD_EN | 0x02 | 1 = grant access to the output buffer. |
| PAG7920_SPI_INT_STATUS | 0x03 | Interrupt flags, write-to-clear. |
| PAG7920_SPI_CHECKID_L | 0x06 | 0x5A |
| PAG7920_SPI_CHECKID_H | 0x07 | 0xA5 |
| PAG7920_SPI_IMG_DATA | 0x40 | Image burst source. |
| PAG7920_SPI_CHECK_ID | 0xA55A | Expected CheckID; 0 unless running. |
| PAG7920_BUFFER_BYTES | 4800 | Output buffer size. A frame is delivered in units of this. |

