Skip to content

Commit

Permalink
Merge pull request #7 from lilrabbits/issue-5
Browse files Browse the repository at this point in the history
Added the code for turning on the LED and overall number of repetitions option
  • Loading branch information
phillipstanleymarbell authored Aug 29, 2018
2 parents 7c624de + b9e89d5 commit 8ddef27
Showing 1 changed file with 115 additions and 10 deletions.
125 changes: 115 additions & 10 deletions src/boot/ksdk1.1.0/warp-kl03-ksdk1.1-boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,8 @@ void
initAS7262(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStatePointer)
{
deviceStatePointer->i2cAddress = i2cAddress;
deviceStatePointer->signalType = ( kWarpTypeMaskLambda450V |
deviceStatePointer->signalType = ( kWarpTypeMaskTemperature|
kWarpTypeMaskLambda450V |
kWarpTypeMaskLambda500B |
kWarpTypeMaskLambda550G |
kWarpTypeMaskLambda570Y |
Expand All @@ -936,7 +937,10 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
/*
* The sensor has only 3 real registers: STATUS Register 0x00, WRITE Register 0x01 and READ register 0x02.
*/
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG,0xFF};
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0xFF};
uint8_t cmdBuf_LEDCTRL[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x87};
uint8_t cmdBuf_LEDON[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x1B};
uint8_t cmdBuf_LEDOFF[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x00};
uint8_t cmdBuf_read[1] = {kWarpI2C_AS726x_SLAVE_READ_REG};
i2c_status_t returnValue;

Expand All @@ -954,7 +958,31 @@ readSensorRegisterAS7262(uint8_t deviceRegister)


cmdBuf_write[1] = deviceRegister;


/*
* The LED control register details can be found in Figure 26 of AS7262 detailed descriptions on page 26.
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* This turns on the LED before reading the data
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDON /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* See Page 8 to Page 11 of AS726X Design Considerations for writing to and reading from virtual registers.
* Write transaction writes the value of the virtual register one wants to read from to the WRITE register 0x01.
Expand All @@ -966,7 +994,7 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);
500 /* timeout in milliseconds */);

/*
* Read transaction which reads from the READ register 0x02.
Expand All @@ -979,7 +1007,7 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
1 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);
500 /* timeout in milliseconds */);

returnValue = I2C_DRV_MasterReceiveDataBlocking(
0 /* I2C peripheral instance */,
Expand All @@ -990,6 +1018,27 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
1 /* The length in bytes of the data to be transferred and data is transferred from the sensor to master via bus */,
500 /* timeout in milliseconds */);

returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* This turns off the LED after finish reading the data
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDOFF /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

if (returnValue == kStatus_I2C_Success)
{
//...
Expand All @@ -1006,7 +1055,8 @@ void
initAS7263(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStatePointer)
{
deviceStatePointer->i2cAddress = i2cAddress;
deviceStatePointer->signalType = ( kWarpTypeMaskLambda610R |
deviceStatePointer->signalType = ( kWarpTypeMaskTemperature|
kWarpTypeMaskLambda610R |
kWarpTypeMaskLambda680S |
kWarpTypeMaskLambda730T |
kWarpTypeMaskLambda760U |
Expand All @@ -1016,13 +1066,17 @@ initAS7263(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStateP
return;
}


WarpStatus
readSensorRegisterAS7263(uint8_t deviceRegister)
{
/*
* The sensor has only 3 real registers: STATUS Register 0x00, WRITE Register 0x01 and READ register 0x02.
*/
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG,0xFF};
uint8_t cmdBuf_LEDCTRL[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x87};
uint8_t cmdBuf_LEDON[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x1B};
uint8_t cmdBuf_LEDOFF[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x00};
uint8_t cmdBuf_read[1] = {kWarpI2C_AS726x_SLAVE_READ_REG};
i2c_status_t returnValue;

Expand All @@ -1040,7 +1094,31 @@ readSensorRegisterAS7263(uint8_t deviceRegister)


cmdBuf_write[1] = deviceRegister;


/*
* The LED control register details can be found in Figure 27 of AS7263 detailed descriptions on page 24.
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* This turns on the LED before reading the data
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDON /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* See Page 8 to Page 11 of AS726X Design Considerations for writing to and reading from virtual registers.
* Write transaction writes the value of the virtual register one wants to read from to the WRITE register 0x01.
Expand Down Expand Up @@ -1076,6 +1154,27 @@ readSensorRegisterAS7263(uint8_t deviceRegister)
1 /* The length in bytes of the data to be transferred and data is transferred from the sensor to master via bus */,
500 /* timeout in milliseconds */);

returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

/*
* This turns off the LED after finish reading the data
*/
returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C peripheral instance */,
&slave /* The pointer to the I2C device information structure */,
cmdBuf_LEDOFF /* The pointer to the commands to be transferred */,
2 /* The length in bytes of the commands to be transferred */,
NULL /* The pointer to the data to be transferred */,
0 /* The length in bytes of the data to be transferred */,
500 /* timeout in milliseconds */);

if (returnValue == kStatus_I2C_Success)
{
//...
Expand Down Expand Up @@ -2292,7 +2391,7 @@ main(void)
case 'j':
{
bool autoIncrement, chatty;
int spinDelay, repetitionsPerAddress, chunkReadsPerAddress;
int spinDelay, repetitionsPerAddress, chunkReadsPerAddress, overallNumberOfRepetitions;
int adaptiveSssupplyMaxMillivolts;
uint8_t referenceByte;

Expand Down Expand Up @@ -2323,11 +2422,16 @@ main(void)

SEGGER_RTT_WriteString(0, "\r\n\tReference byte for comparisons (e.g., '3e')> ");brieflyToggleEnablingSWD();
referenceByte = readHexByte();

SEGGER_RTT_WriteString(0, "\r\n\tOverall number of repetitions (e.g., '0000')> ");brieflyToggleEnablingSWD();
overallNumberOfRepetitions = read4digits();

SEGGER_RTT_printf(0, "\r\n\tRepeating dev%d @ 0x%02x, reps=%d, pull=%d, delay=%dms:\n\n",
menuTargetSensor, menuRegisterAddress, repetitionsPerAddress, menuI2cPullupEnable, spinDelay);brieflyToggleEnablingSWD();

repeatRegisterReadForDeviceAndAddress( menuTargetSensor /*warpSensorDevice*/,
for (int i = 0; i < overallNumberOfRepetitions; i++)
{
repeatRegisterReadForDeviceAndAddress( menuTargetSensor /*warpSensorDevice*/,
menuRegisterAddress /*baseAddress */,
menuI2cPullupEnable,
autoIncrement /*autoIncrement*/,
Expand All @@ -2339,6 +2443,7 @@ main(void)
adaptiveSssupplyMaxMillivolts,
referenceByte
);
}

break;
}
Expand Down Expand Up @@ -3572,4 +3677,4 @@ activateAllLowPowerSensorModes(void)
* For now, simply hold its reset line low.
*/
GPIO_DRV_ClearPinOutput(kWarpPinADXL362_CS_PAN1326_nSHUTD);
}
}

0 comments on commit 8ddef27

Please sign in to comment.