Finished getting data from the sensor camera.

This commit is contained in:
Pcornat 2025-02-16 19:54:08 +01:00
parent 256cd3c500
commit 98c5793738
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
2 changed files with 112 additions and 15 deletions

View file

@ -30,6 +30,11 @@ typedef enum {
stop
} StepArrayRetrieve;
typedef enum {
top_mat = 0,
bot_mat
} ArrayPart;
typedef enum {
cam_blk_0 = 0,
cam_blk_1 = 1 << 4,

View file

@ -63,17 +63,15 @@ static void MX_NVIC_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
volatile ArrayResgiters array_part = data_top_reg;
#define LINE_SIZE 32
#define BLK_SIZE 128
#define SENSOR_SIZE 1024
volatile ArrayPart array_part = top_mat;
volatile StepArrayRetrieve block_step = top_block_0;
const uint8_t part_half_array = 256;
const uint8_t ptat_num = 1;
const uint8_t total_array_size = 1024;
uint16_t top_blk0[part_half_array + ptat_num] = { 0 };
uint16_t top_blk1[part_half_array + ptat_num] = { 0 };
uint16_t top_blk2[part_half_array + ptat_num] = { 0 };
uint16_t top_blk3[part_half_array + ptat_num] = { 0 };
uint16_t bot_blk0[part_half_array + ptat_num] = { 0 };
uint16_t complete_array[total_array_size] = { 0 };
uint16_t tmp_blk0[BLK_SIZE + 1] = { 0 };
uint16_t tmp_blk1[BLK_SIZE + 1] = { 0 };
uint16_t complete_array[SENSOR_SIZE] = { 0 };
void configure_sensor() {
uint8_t data = 1;
@ -110,38 +108,132 @@ void configure_sensor() {
HAL_Delay(6);
}
int8_t blk_offset_start(const StepArrayRetrieve blk_step) {
switch (blk_step) {
case top_block_0:
return 0;
case top_block_1:
return 1;
case top_block_2:
return 2;
case top_block_3:
return 3;
case bot_block_0:
return 31;
case bot_block_1:
return 30;
case bot_block_2:
return 29;
case bot_block_3:
return 28;
default:
return 0;
}
}
void copy_line(const uint16_t *restrict const blk, const int8_t j, const int8_t count) {
for (int8_t i = 0; i < LINE_SIZE; ++i) {
complete_array[j * LINE_SIZE + i] = blk[count * LINE_SIZE + i];
}
}
void transfer_blk_to_array(const uint16_t *restrict const blk,
const ArrayPart top_bot,
const StepArrayRetrieve blk_step
) {
const int8_t offset = blk_offset_start(blk_step);
switch (top_bot) {
case top_mat:
for (int8_t j = offset, count = 0; count < 4; j += 4, ++count) {
copy_line(blk, j, count);
}
break;
case bot_mat:
for (int8_t j = offset, count = 0; count < 4; j -= 4, ++count) {
copy_line(blk, j, count);
}
break;
}
}
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) {
switch (block_step) {
case top_block_0:
block_step = top_block_1;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
data_top_reg | start_get_mat,
cam_blk_1 | data_top_reg | start_get_mat,
1,
(uint8_t *) top_blk0,
sizeof(top_blk0) * sizeof(uint16_t));
(uint8_t *) tmp_blk1,
sizeof(tmp_blk1) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk0, top_mat, top_block_0);
break;
case top_block_1:
block_step = top_block_2;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_2 | data_top_reg | start_get_mat,
1,
(uint8_t *) tmp_blk0,
sizeof(tmp_blk0) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk1, top_mat, top_block_1);
break;
case top_block_2:
block_step = top_block_3;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_3 | data_top_reg | start_get_mat,
1,
(uint8_t *) tmp_blk1,
sizeof(tmp_blk1) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk0, top_mat, top_block_2);
break;
case top_block_3:
block_step = bot_block_0;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_0 | data_bot_reg | start_get_mat,
1,
(uint8_t *) tmp_blk0,
sizeof(tmp_blk0) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk1, top_mat, top_block_3);
break;
case bot_block_0:
block_step = bot_block_1;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_1 | data_top_reg | start_get_mat,
1,
(uint8_t *) tmp_blk1,
sizeof(tmp_blk1) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk0, bot_mat, bot_block_0);
break;
case bot_block_1:
block_step = bot_block_2;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_2 | data_top_reg | start_get_mat,
1,
(uint8_t *) tmp_blk0,
sizeof(tmp_blk0) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk1, bot_mat, bot_block_1);
break;
case bot_block_2:
block_step = bot_block_3;
HAL_I2C_Mem_Read_IT(&hi2c1,
sensor_addr,
cam_blk_3 | data_top_reg | start_get_mat,
1,
(uint8_t *) tmp_blk1,
sizeof(tmp_blk1) * sizeof(uint16_t));
transfer_blk_to_array(tmp_blk0, top_mat, top_block_2);
break;
case bot_block_3:
block_step = stop;
transfer_blk_to_array(tmp_blk1, bot_mat, bot_block_3);
break;
default:
block_step = stop;
break;
}
}
@ -190,8 +282,8 @@ int main(void) {
sensor_addr,
data_top_reg,
1,
(uint8_t *) &top_blk0,
part_half_array * sizeof(uint16_t),
(uint8_t *) &tmp_blk0,
sizeof(tmp_blk0) * sizeof(uint16_t),
5);
/* USER CODE END 2 */