Skip to content

Commit

Permalink
Merge pull request #5 from neurogears/fw-create_3_new_registers
Browse files Browse the repository at this point in the history
Create ability to read flow meter IDs and configure the count per inch.
  • Loading branch information
filcarv authored Oct 16, 2023
2 parents a023556 + 99aa5ad commit cc194e6
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Firmware/VestibularH1/PAA5100JE.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <util/delay.h>

Motion th;

extern uint8_t prodIdPort0;
extern uint8_t prodIdPort1;

bool optical_tracking_initialize_flow0(void)
{
/* Power up and reset */
Expand All @@ -18,6 +22,8 @@ bool optical_tracking_initialize_flow0(void)

if (productID != 0x49 || invProductID != 0xB6)
return false;
else
prodIdPort0 = 0x49;

/* Read the data registers */
optical_tracking_read_register_flow0(MOTION_REG_ADD);
Expand Down Expand Up @@ -45,6 +51,8 @@ bool optical_tracking_initialize_flow1(void)

if (productID != 0x49 || invProductID != 0xB6)
return false;
else
prodIdPort1 = 0x49;

/* Read the data registers */
optical_tracking_read_register_flow1(MOTION_REG_ADD);
Expand Down
21 changes: 13 additions & 8 deletions Firmware/VestibularH1/PMW3360.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ uint8_t productID;
uint8_t invProductID;
uint8_t sromID;

uint16_t cpi;
extern uint8_t prodIdPort0;
extern uint8_t prodIdPort1;

bool optical_tracking_initialize_pwm3360_0(void)
{
Expand All @@ -32,6 +33,8 @@ bool optical_tracking_initialize_pwm3360_0(void)
uint8_t prodID = check_signatures_pmw3360_0(false);
if (prodID == 0)
return false;
else
prodIdPort0 = prodID;

/* Read the data registers */
optical_tracking_read_register_pwm3360_0(REG_Motion);
Expand Down Expand Up @@ -73,7 +76,9 @@ bool optical_tracking_initialize_pwm3360_1(void)
/* Check if the right IC is present */
uint8_t prodID = check_signatures_pmw3360_1(false);
if (prodID == 0)
return false;
return false;
else
prodIdPort1 = prodID;

/* Read the data registers */
optical_tracking_read_register_pwm3360_1(REG_Motion);
Expand Down Expand Up @@ -668,11 +673,11 @@ void optical_tracking_write_register_pmw3360_0(uint8_t address, uint8_t byte)
//_delay_us(1);
//_delay_us(10);
spi_tx_byte_flow0(byte);
_delay_us(20); // Increased to 20 microseconds
_delay_us(1); // Increased to 20 microseconds
_delay_us(20);
_delay_us(1);
spi_stop_flow0();

_delay_us(100); // Added this delay
_delay_us(20);
}

void optical_tracking_write_register_pmw3360_1(uint8_t address, uint8_t byte)
Expand All @@ -686,9 +691,9 @@ void optical_tracking_write_register_pmw3360_1(uint8_t address, uint8_t byte)
//_delay_us(1);
//_delay_us(10);
spi_tx_byte_flow1(byte);
_delay_us(20); // Increased to 20 microseconds
_delay_us(1); // Increased to 20 microseconds
_delay_us(20);
_delay_us(1);
spi_stop_flow1();

_delay_us(100); // Added this delay
_delay_us(20);
}
62 changes: 60 additions & 2 deletions Firmware/VestibularH1/app_funcs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "app_funcs.h"
#include "app_ios_and_regs.h"
#include "hwbp_core.h"
#include "PMW3360.h"


/************************************************************************/
Expand All @@ -23,7 +24,10 @@ void (*app_func_rd_pointer[])(void) = {
&app_read_REG_OUT_CLEAR,
&app_read_REG_OUT_TOGGLE,
&app_read_REG_OUT_WRITE,
&app_read_REG_REG_OPTICAL_TRACKING_READ
&app_read_REG_REG_OPTICAL_TRACKING_READ,
&app_read_REG_PRODUCT_ID_PORT0,
&app_read_REG_PRODUCT_ID_PORT1,
&app_read_REG_CPI
};

bool (*app_func_wr_pointer[])(void*) = {
Expand All @@ -41,7 +45,10 @@ bool (*app_func_wr_pointer[])(void*) = {
&app_write_REG_OUT_CLEAR,
&app_write_REG_OUT_TOGGLE,
&app_write_REG_OUT_WRITE,
&app_write_REG_REG_OPTICAL_TRACKING_READ
&app_write_REG_REG_OPTICAL_TRACKING_READ,
&app_write_REG_PRODUCT_ID_PORT0,
&app_write_REG_PRODUCT_ID_PORT1,
&app_write_REG_CPI
};


Expand Down Expand Up @@ -423,4 +430,55 @@ void app_read_REG_REG_OPTICAL_TRACKING_READ(void) {}
bool app_write_REG_REG_OPTICAL_TRACKING_READ(void *a)
{
return false;
}




/************************************************************************/
/* REG_PRODUCT_ID_PORT0 */
/************************************************************************/
uint8_t prodIdPort0;

void app_read_REG_PRODUCT_ID_PORT0(void)
{
app_regs.REG_PRODUCT_ID_PORT0 = prodIdPort0;
}
bool app_write_REG_PRODUCT_ID_PORT0(void *a)
{
return false;
}



/************************************************************************/
/* REG_PRODUCT_ID_PORT1 */
/************************************************************************/
uint8_t prodIdPort1;

void app_read_REG_PRODUCT_ID_PORT1(void)
{
app_regs.REG_PRODUCT_ID_PORT1 = prodIdPort1;
}
bool app_write_REG_PRODUCT_ID_PORT1(void *a)
{
return false;
}




/************************************************************************/
/* REG_CPI */
/************************************************************************/
void app_read_REG_CPI(void) {}
bool app_write_REG_CPI(void *a)
{
uint16_t reg = *((uint16_t*)a);

set_cpi_pmw3360_0(reg);
set_cpi_pmw3360_1(reg);

app_regs.REG_CPI = reg;
return true;
}
6 changes: 6 additions & 0 deletions Firmware/VestibularH1/app_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void app_read_REG_OUT_CLEAR(void);
void app_read_REG_OUT_TOGGLE(void);
void app_read_REG_OUT_WRITE(void);
void app_read_REG_REG_OPTICAL_TRACKING_READ(void);
void app_read_REG_PRODUCT_ID_PORT0(void);
void app_read_REG_PRODUCT_ID_PORT1(void);
void app_read_REG_CPI(void);

bool app_write_REG_CAM0_EVENT(void *a);
bool app_write_REG_CAM1_EVENT(void *a);
Expand All @@ -51,6 +54,9 @@ bool app_write_REG_OUT_CLEAR(void *a);
bool app_write_REG_OUT_TOGGLE(void *a);
bool app_write_REG_OUT_WRITE(void *a);
bool app_write_REG_REG_OPTICAL_TRACKING_READ(void *a);
bool app_write_REG_PRODUCT_ID_PORT0(void *a);
bool app_write_REG_PRODUCT_ID_PORT1(void *a);
bool app_write_REG_CPI(void *a);


#endif /* _APP_FUNCTIONS_H_ */
15 changes: 12 additions & 3 deletions Firmware/VestibularH1/app_ios_and_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ uint8_t app_regs_type[] = {
TYPE_U8,
TYPE_U8,
TYPE_U8,
TYPE_I16
TYPE_I16,
TYPE_U8,
TYPE_U8,
TYPE_U16
};

uint16_t app_regs_n_elements[] = {
Expand All @@ -79,7 +82,10 @@ uint16_t app_regs_n_elements[] = {
1,
1,
1,
6
6,
1,
1,
1
};

uint8_t *app_regs_pointer[] = {
Expand All @@ -97,5 +103,8 @@ uint8_t *app_regs_pointer[] = {
(uint8_t*)(&app_regs.REG_OUT_CLEAR),
(uint8_t*)(&app_regs.REG_OUT_TOGGLE),
(uint8_t*)(&app_regs.REG_OUT_WRITE),
(uint8_t*)(app_regs.REG_REG_OPTICAL_TRACKING_READ)
(uint8_t*)(app_regs.REG_REG_OPTICAL_TRACKING_READ),
(uint8_t*)(&app_regs.REG_PRODUCT_ID_PORT0),
(uint8_t*)(&app_regs.REG_PRODUCT_ID_PORT1),
(uint8_t*)(&app_regs.REG_CPI)
};
12 changes: 8 additions & 4 deletions Firmware/VestibularH1/app_ios_and_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ typedef struct
uint8_t REG_OUT_TOGGLE;
uint8_t REG_OUT_WRITE;
int16_t REG_REG_OPTICAL_TRACKING_READ[6];
uint8_t REG_PRODUCT_ID_PORT0;
uint8_t REG_PRODUCT_ID_PORT1;
uint16_t REG_CPI;
} AppRegs;

/************************************************************************/
Expand All @@ -135,6 +138,9 @@ typedef struct
#define ADD_REG_OUT_TOGGLE 44 // U8 Bitmask to toggle the digital ouputs
#define ADD_REG_OUT_WRITE 45 // U8 Bitmask to write the digital ouputs
#define ADD_REG_REG_OPTICAL_TRACKING_READ 46 // I16
#define ADD_REG_PRODUCT_ID_PORT0 47 // U8 Contains de flow meter ID connected to Port 0
#define ADD_REG_PRODUCT_ID_PORT1 48 // U8 Contains de flow meter ID connected to Port 1
#define ADD_REG_CPI 49 // U16 Configures the counts per inch for both channels (PMW3360 only)

/************************************************************************/
/* PWM Generator registers' memory limits */
Expand All @@ -144,15 +150,13 @@ typedef struct
/************************************************************************/
/* Memory limits */
#define APP_REGS_ADD_MIN 0x20
#define APP_REGS_ADD_MAX 0x2E
#define APP_NBYTES_OF_REG_BANK 30
#define APP_REGS_ADD_MAX 0x31
#define APP_NBYTES_OF_REG_BANK 34

/************************************************************************/
/* Registers' bits */
/************************************************************************/
#define B_TRIGGER (1<<0) // A trigger was sent to camera
#define MSK_STROBE_DIRECT 0 // Selects the direct line
#define MSK_STROBE_PULL_UP 1 // Selects the pull-up line
#define B_START_CAM0 (1<<0) //
#define B_START_CAM1 (1<<1) //
#define B_STOP_CAM0 (1<<2) //
Expand Down
Binary file modified Firmware/VestibularH1/registers.xls
Binary file not shown.

0 comments on commit cc194e6

Please sign in to comment.