File ns_camera.c
FileList > neuralSPOT > neuralspot > ns-camera > src > ns_camera.c
Go to the source code of this file
#include <stdlib.h>#include "ns_camera.h"#include "ArducamCamera.h"#include "arm_math.h"#include "jpeg-decoder/jpeg_decoder.h"#include "jpeg-decoder/picojpeg.h"#include "ns_spi.h"#include "ns_ambiqsuite_harness.h"
Public Attributes
| Type | Name |
|---|---|
| ArducamCamera | camera |
| jpeg_decoder_context_t | jpegCtx = {} |
| bool | nsCameraPictureBeingTaken = false |
| const ns_core_api_t | ns_camera_V1_0_0 = {.apiId = NS\_CAMERA\_API\_ID, .version = NS\_CAMERA\_V1\_0\_0} |
| ns_camera_config_t | ns_camera_config |
| const ns_core_api_t | ns_camera_current_version = /* multi line expression */ |
| const ns_core_api_t | ns_camera_oldest_supported_version = /* multi line expression */ |
| bool | ns_read_done = false |
| ns_spi_config_t * | spiHandle = NULL |
| ns_timer_config_t | timerCfg = /* multi line expression */ |
Public Static Attributes
| Type | Name |
|---|---|
| uint8_t * | dma_cambuf |
| uint32_t | dma_current_chunk_length |
| uint32_t | dma_offset |
| uint32_t | dma_total_requested_length |
Public Functions
| Type | Name |
|---|---|
| void | arducam_delay_ms (uint16_t delay) |
| void | arducam_delay_us (uint16_t delay) |
| int | arducam_spi_read (const void * buf, uint32_t bufLen, uint64_t reg, uint32_t regLen, uint32_t csPin) |
| int | arducam_spi_write (const void * buf, uint32_t bufLen, uint64_t reg, uint32_t regLen, uint32_t csPin) |
| int | camera_decode_image (uint8_t * camBuf, uint32_t camLen, uint8_t * imgBuf, uint32_t imgWidth, uint32_t imgHeight, uint32_t scaleFactor) Decode a JPEG image from the camera buffer to RGB565 buffer. |
| void | ns_camera_adjust_settings (int8_t contrast, int8_t brightness, int8_t ev) Adjust camera settings. |
| uint32_t | ns_camera_capture (ns_camera_config_t * cfg, uint8_t * camBuf, uint32_t bufLen) Convenience routine to capture and transfer next frame. |
| void | ns_camera_check_picture_completion (ns_timer_config_t * timer) |
| uint32_t | ns_camera_init (ns_camera_config_t * cfg) Initialize the camera. |
| uint32_t | ns_chop_off_trailing_zeros (uint8_t * buff, uint32_t length) Chop off trailing zeros from a buffer. |
| int | ns_is_camera_capturing () Check if camera is still capturing This is a helper function, it should typically only be used by ns_camera. |
| uint32_t | ns_press_shutter_button (ns_camera_config_t * cfg) Press the shutter button Start the capture process, turns on a timer to poll the camera for completion. |
| uint32_t | ns_read_buff (ArducamCamera * camera, uint8_t * buff, uint32_t length) |
| void | ns_rgb565_to_rgb888 (uint16_t rgb565Pixel, uint8_t * r, uint8_t * g, uint8_t * b) |
| uint32_t | ns_start_camera (ns_camera_config_t * cfg) Start the camera (take out of low power mode) |
| uint32_t | ns_start_dma_read (ns_camera_config_t * cfg, uint8_t * camBuf, uint32_t * buffer_offset, uint32_t bufLen) Start a DMA read of the camera buffer. |
| uint32_t | ns_stop_camera (ns_camera_config_t * cfg) Stop the camera (put into low power mode) |
| uint32_t | ns_take_picture (ns_camera_config_t * cfg) Take a picture in mode specified by cfg Once picture is taken, it can be transferred using ns_transfer_picture. |
| uint32_t | ns_transfer_picture (ns_camera_config_t * cfg, uint8_t * camBuf, uint32_t * buffer_offset, uint32_t bufLen) Transfer captured frame over SPI to local buffer NOTE: This routine is blocking and will wait for inflight capture. |
Public Static Functions
| Type | Name |
|---|---|
| void | ns_camera_buff_read_done (ns_spi_config_t * cfg) |
| uint8_t | ns_mapCameraValuesToArducamScale (int8_t in) |
Macros
| Type | Name |
|---|---|
| define | ARDU_BURST_FIFO_READ 0x3C |
| define | MAX_SPI_BUF_LEN 64 |
| define | MAX_SPI_DMA_LEN 4095 |
| define | NS_CAMERA_ARDUCHIP_TRIG 0x44 |
| define | NS_CAMERA_CAP_DONE_MASK 0x04 |
| define | NS_CAMERA_SHUTTER_MASK 0x02 |
| define | NS_CAMERA_VSYNC_MASK 0x01 |
| define | NS_CAM_REG_CAPTURE_RESOLUTION 0X21 |
| define | NS_CAM_REG_FORMAT 0X20 |
| define | NS_CAM_SET_CAPTURE_MODE (0 << 7) |
Public Attributes Documentation
variable camera
ArducamCamera camera;
variable jpegCtx
jpeg_decoder_context_t jpegCtx;
variable nsCameraPictureBeingTaken
bool nsCameraPictureBeingTaken;
variable ns_camera_V1_0_0
const ns_core_api_t ns_camera_V1_0_0;
variable ns_camera_config
ns_camera_config_t ns_camera_config;
variable ns_camera_current_version
const ns_core_api_t ns_camera_current_version;
variable ns_camera_oldest_supported_version
const ns_core_api_t ns_camera_oldest_supported_version;
variable ns_read_done
bool ns_read_done;
variable spiHandle
ns_spi_config_t* spiHandle;
variable timerCfg
ns_timer_config_t timerCfg;
Public Static Attributes Documentation
variable dma_cambuf
uint8_t* dma_cambuf;
variable dma_current_chunk_length
uint32_t dma_current_chunk_length;
variable dma_offset
uint32_t dma_offset;
variable dma_total_requested_length
uint32_t dma_total_requested_length;
Public Functions Documentation
function arducam_delay_ms
void arducam_delay_ms (
uint16_t delay
)
function arducam_delay_us
void arducam_delay_us (
uint16_t delay
)
function arducam_spi_read
int arducam_spi_read (
const void * buf,
uint32_t bufLen,
uint64_t reg,
uint32_t regLen,
uint32_t csPin
)
function arducam_spi_write
int arducam_spi_write (
const void * buf,
uint32_t bufLen,
uint64_t reg,
uint32_t regLen,
uint32_t csPin
)
function camera_decode_image
Decode a JPEG image from the camera buffer to RGB565 buffer.
int camera_decode_image (
uint8_t * camBuf,
uint32_t camLen,
uint8_t * imgBuf,
uint32_t imgWidth,
uint32_t imgHeight,
uint32_t scaleFactor
)
Converts a JPG to an RGB565 image.
Parameters:
camBufCamera buffer to decodecamLenLength of camera bufferimgBufImage buffer to store decoded imageimgWidthWidth of imageimgHeightHeight of imagescaleFactorScale factor for image
Returns:
int
function ns_camera_adjust_settings
Adjust camera settings.
void ns_camera_adjust_settings (
int8_t contrast,
int8_t brightness,
int8_t ev
)
Parameters:
contrastbrightnessev
function ns_camera_capture
Convenience routine to capture and transfer next frame.
uint32_t ns_camera_capture (
ns_camera_config_t * cfg,
uint8_t * camBuf,
uint32_t bufLen
)
Parameters:
camBufCamera buffer to store framebufLenBuffer size
Returns:
uint32_t
function ns_camera_check_picture_completion
void ns_camera_check_picture_completion (
ns_timer_config_t * timer
)
function ns_camera_init
Initialize the camera.
uint32_t ns_camera_init (
ns_camera_config_t * cfg
)
Parameters:
cfg
Returns:
uint32_t
function ns_chop_off_trailing_zeros
Chop off trailing zeros from a buffer.
uint32_t ns_chop_off_trailing_zeros (
uint8_t * buff,
uint32_t length
)
Parameters:
buffJPG bufferlengthAdjusted length after trailing zeros are removed
Returns:
uint32_t
function ns_is_camera_capturing
Check if camera is still capturing This is a helper function, it should typically only be used by ns_camera.
int ns_is_camera_capturing ()
Returns:
int
function ns_press_shutter_button
Press the shutter button Start the capture process, turns on a timer to poll the camera for completion.
uint32_t ns_press_shutter_button (
ns_camera_config_t * cfg
)
Parameters:
cfg
Returns:
uint32_t
function ns_read_buff
uint32_t ns_read_buff (
ArducamCamera * camera,
uint8_t * buff,
uint32_t length
)
function ns_rgb565_to_rgb888
void ns_rgb565_to_rgb888 (
uint16_t rgb565Pixel,
uint8_t * r,
uint8_t * g,
uint8_t * b
)
function ns_start_camera
Start the camera (take out of low power mode)
uint32_t ns_start_camera (
ns_camera_config_t * cfg
)
Parameters:
cfg
Returns:
uint32_t
function ns_start_dma_read
Start a DMA read of the camera buffer.
uint32_t ns_start_dma_read (
ns_camera_config_t * cfg,
uint8_t * camBuf,
uint32_t * buffer_offset,
uint32_t bufLen
)
Parameters:
cfgcamBufBuffer to store imagebuffer_offsetReturned value of buffer offsetbufLenLength of buffer
Returns:
uint32_t Total size of image in bytes
function ns_stop_camera
Stop the camera (put into low power mode)
uint32_t ns_stop_camera (
ns_camera_config_t * cfg
)
Parameters:
cfg
Returns:
uint32_t
function ns_take_picture
Take a picture in mode specified by cfg Once picture is taken, it can be transferred using ns_transfer_picture.
uint32_t ns_take_picture (
ns_camera_config_t * cfg
)
Parameters:
cfg
Returns:
uint32_t
function ns_transfer_picture
Transfer captured frame over SPI to local buffer NOTE: This routine is blocking and will wait for inflight capture.
uint32_t ns_transfer_picture (
ns_camera_config_t * cfg,
uint8_t * camBuf,
uint32_t * buffer_offset,
uint32_t bufLen
)
Parameters:
cfgcamBufCamera buffer to store framebuffer_offsetJPG images are stored 1 byte offset from start of buffer, so use this to find itbufLenBuffer size
Returns:
uint32_t
Public Static Functions Documentation
function ns_camera_buff_read_done
static void ns_camera_buff_read_done (
ns_spi_config_t * cfg
)
function ns_mapCameraValuesToArducamScale
static uint8_t ns_mapCameraValuesToArducamScale (
int8_t in
)
Macro Definition Documentation
define ARDU_BURST_FIFO_READ
#define ARDU_BURST_FIFO_READ `0x3C`
define MAX_SPI_BUF_LEN
#define MAX_SPI_BUF_LEN `64`
define MAX_SPI_DMA_LEN
#define MAX_SPI_DMA_LEN `4095`
define NS_CAMERA_ARDUCHIP_TRIG
#define NS_CAMERA_ARDUCHIP_TRIG `0x44`
define NS_CAMERA_CAP_DONE_MASK
#define NS_CAMERA_CAP_DONE_MASK `0x04`
define NS_CAMERA_SHUTTER_MASK
#define NS_CAMERA_SHUTTER_MASK `0x02`
define NS_CAMERA_VSYNC_MASK
#define NS_CAMERA_VSYNC_MASK `0x01`
define NS_CAM_REG_CAPTURE_RESOLUTION
#define NS_CAM_REG_CAPTURE_RESOLUTION `0X21`
define NS_CAM_REG_FORMAT
#define NS_CAM_REG_FORMAT `0X20`
define NS_CAM_SET_CAPTURE_MODE
#define NS_CAM_SET_CAPTURE_MODE `(0 << 7)`
The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-camera/src/ns_camera.c