Skip to content

Commit 8ddef27

Browse files
Merge pull request #7 from lilrabbits/issue-5
Added the code for turning on the LED and overall number of repetitions option
2 parents 7c624de + b9e89d5 commit 8ddef27

File tree

1 file changed

+115
-10
lines changed

1 file changed

+115
-10
lines changed

src/boot/ksdk1.1.0/warp-kl03-ksdk1.1-boot.c

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,8 @@ void
920920
initAS7262(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStatePointer)
921921
{
922922
deviceStatePointer->i2cAddress = i2cAddress;
923-
deviceStatePointer->signalType = ( kWarpTypeMaskLambda450V |
923+
deviceStatePointer->signalType = ( kWarpTypeMaskTemperature|
924+
kWarpTypeMaskLambda450V |
924925
kWarpTypeMaskLambda500B |
925926
kWarpTypeMaskLambda550G |
926927
kWarpTypeMaskLambda570Y |
@@ -936,7 +937,10 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
936937
/*
937938
* The sensor has only 3 real registers: STATUS Register 0x00, WRITE Register 0x01 and READ register 0x02.
938939
*/
939-
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG,0xFF};
940+
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0xFF};
941+
uint8_t cmdBuf_LEDCTRL[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x87};
942+
uint8_t cmdBuf_LEDON[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x1B};
943+
uint8_t cmdBuf_LEDOFF[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x00};
940944
uint8_t cmdBuf_read[1] = {kWarpI2C_AS726x_SLAVE_READ_REG};
941945
i2c_status_t returnValue;
942946

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

955959

956960
cmdBuf_write[1] = deviceRegister;
957-
961+
962+
/*
963+
* The LED control register details can be found in Figure 26 of AS7262 detailed descriptions on page 26.
964+
*/
965+
returnValue = I2C_DRV_MasterSendDataBlocking(
966+
0 /* I2C peripheral instance */,
967+
&slave /* The pointer to the I2C device information structure */,
968+
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
969+
2 /* The length in bytes of the commands to be transferred */,
970+
NULL /* The pointer to the data to be transferred */,
971+
0 /* The length in bytes of the data to be transferred */,
972+
500 /* timeout in milliseconds */);
973+
974+
/*
975+
* This turns on the LED before reading the data
976+
*/
977+
returnValue = I2C_DRV_MasterSendDataBlocking(
978+
0 /* I2C peripheral instance */,
979+
&slave /* The pointer to the I2C device information structure */,
980+
cmdBuf_LEDON /* The pointer to the commands to be transferred */,
981+
2 /* The length in bytes of the commands to be transferred */,
982+
NULL /* The pointer to the data to be transferred */,
983+
0 /* The length in bytes of the data to be transferred */,
984+
500 /* timeout in milliseconds */);
985+
958986
/*
959987
* See Page 8 to Page 11 of AS726X Design Considerations for writing to and reading from virtual registers.
960988
* Write transaction writes the value of the virtual register one wants to read from to the WRITE register 0x01.
@@ -966,7 +994,7 @@ readSensorRegisterAS7262(uint8_t deviceRegister)
966994
2 /* The length in bytes of the commands to be transferred */,
967995
NULL /* The pointer to the data to be transferred */,
968996
0 /* The length in bytes of the data to be transferred */,
969-
500 /* timeout in milliseconds */);
997+
500 /* timeout in milliseconds */);
970998

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

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

1021+
returnValue = I2C_DRV_MasterSendDataBlocking(
1022+
0 /* I2C peripheral instance */,
1023+
&slave /* The pointer to the I2C device information structure */,
1024+
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
1025+
2 /* The length in bytes of the commands to be transferred */,
1026+
NULL /* The pointer to the data to be transferred */,
1027+
0 /* The length in bytes of the data to be transferred */,
1028+
500 /* timeout in milliseconds */);
1029+
1030+
/*
1031+
* This turns off the LED after finish reading the data
1032+
*/
1033+
returnValue = I2C_DRV_MasterSendDataBlocking(
1034+
0 /* I2C peripheral instance */,
1035+
&slave /* The pointer to the I2C device information structure */,
1036+
cmdBuf_LEDOFF /* The pointer to the commands to be transferred */,
1037+
2 /* The length in bytes of the commands to be transferred */,
1038+
NULL /* The pointer to the data to be transferred */,
1039+
0 /* The length in bytes of the data to be transferred */,
1040+
500 /* timeout in milliseconds */);
1041+
9931042
if (returnValue == kStatus_I2C_Success)
9941043
{
9951044
//...
@@ -1006,7 +1055,8 @@ void
10061055
initAS7263(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStatePointer)
10071056
{
10081057
deviceStatePointer->i2cAddress = i2cAddress;
1009-
deviceStatePointer->signalType = ( kWarpTypeMaskLambda610R |
1058+
deviceStatePointer->signalType = ( kWarpTypeMaskTemperature|
1059+
kWarpTypeMaskLambda610R |
10101060
kWarpTypeMaskLambda680S |
10111061
kWarpTypeMaskLambda730T |
10121062
kWarpTypeMaskLambda760U |
@@ -1016,13 +1066,17 @@ initAS7263(const uint8_t i2cAddress, WarpI2CDeviceState volatile * deviceStateP
10161066
return;
10171067
}
10181068

1069+
10191070
WarpStatus
10201071
readSensorRegisterAS7263(uint8_t deviceRegister)
10211072
{
10221073
/*
10231074
* The sensor has only 3 real registers: STATUS Register 0x00, WRITE Register 0x01 and READ register 0x02.
10241075
*/
10251076
uint8_t cmdBuf_write[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG,0xFF};
1077+
uint8_t cmdBuf_LEDCTRL[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x87};
1078+
uint8_t cmdBuf_LEDON[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x1B};
1079+
uint8_t cmdBuf_LEDOFF[2] = {kWarpI2C_AS726x_SLAVE_WRITE_REG, 0x00};
10261080
uint8_t cmdBuf_read[1] = {kWarpI2C_AS726x_SLAVE_READ_REG};
10271081
i2c_status_t returnValue;
10281082

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

10411095

10421096
cmdBuf_write[1] = deviceRegister;
1043-
1097+
1098+
/*
1099+
* The LED control register details can be found in Figure 27 of AS7263 detailed descriptions on page 24.
1100+
*/
1101+
returnValue = I2C_DRV_MasterSendDataBlocking(
1102+
0 /* I2C peripheral instance */,
1103+
&slave /* The pointer to the I2C device information structure */,
1104+
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
1105+
2 /* The length in bytes of the commands to be transferred */,
1106+
NULL /* The pointer to the data to be transferred */,
1107+
0 /* The length in bytes of the data to be transferred */,
1108+
500 /* timeout in milliseconds */);
1109+
1110+
/*
1111+
* This turns on the LED before reading the data
1112+
*/
1113+
returnValue = I2C_DRV_MasterSendDataBlocking(
1114+
0 /* I2C peripheral instance */,
1115+
&slave /* The pointer to the I2C device information structure */,
1116+
cmdBuf_LEDON /* The pointer to the commands to be transferred */,
1117+
2 /* The length in bytes of the commands to be transferred */,
1118+
NULL /* The pointer to the data to be transferred */,
1119+
0 /* The length in bytes of the data to be transferred */,
1120+
500 /* timeout in milliseconds */);
1121+
10441122
/*
10451123
* See Page 8 to Page 11 of AS726X Design Considerations for writing to and reading from virtual registers.
10461124
* Write transaction writes the value of the virtual register one wants to read from to the WRITE register 0x01.
@@ -1076,6 +1154,27 @@ readSensorRegisterAS7263(uint8_t deviceRegister)
10761154
1 /* The length in bytes of the data to be transferred and data is transferred from the sensor to master via bus */,
10771155
500 /* timeout in milliseconds */);
10781156

1157+
returnValue = I2C_DRV_MasterSendDataBlocking(
1158+
0 /* I2C peripheral instance */,
1159+
&slave /* The pointer to the I2C device information structure */,
1160+
cmdBuf_LEDCTRL /* The pointer to the commands to be transferred */,
1161+
2 /* The length in bytes of the commands to be transferred */,
1162+
NULL /* The pointer to the data to be transferred */,
1163+
0 /* The length in bytes of the data to be transferred */,
1164+
500 /* timeout in milliseconds */);
1165+
1166+
/*
1167+
* This turns off the LED after finish reading the data
1168+
*/
1169+
returnValue = I2C_DRV_MasterSendDataBlocking(
1170+
0 /* I2C peripheral instance */,
1171+
&slave /* The pointer to the I2C device information structure */,
1172+
cmdBuf_LEDOFF /* The pointer to the commands to be transferred */,
1173+
2 /* The length in bytes of the commands to be transferred */,
1174+
NULL /* The pointer to the data to be transferred */,
1175+
0 /* The length in bytes of the data to be transferred */,
1176+
500 /* timeout in milliseconds */);
1177+
10791178
if (returnValue == kStatus_I2C_Success)
10801179
{
10811180
//...
@@ -2292,7 +2391,7 @@ main(void)
22922391
case 'j':
22932392
{
22942393
bool autoIncrement, chatty;
2295-
int spinDelay, repetitionsPerAddress, chunkReadsPerAddress;
2394+
int spinDelay, repetitionsPerAddress, chunkReadsPerAddress, overallNumberOfRepetitions;
22962395
int adaptiveSssupplyMaxMillivolts;
22972396
uint8_t referenceByte;
22982397

@@ -2323,11 +2422,16 @@ main(void)
23232422

23242423
SEGGER_RTT_WriteString(0, "\r\n\tReference byte for comparisons (e.g., '3e')> ");brieflyToggleEnablingSWD();
23252424
referenceByte = readHexByte();
2425+
2426+
SEGGER_RTT_WriteString(0, "\r\n\tOverall number of repetitions (e.g., '0000')> ");brieflyToggleEnablingSWD();
2427+
overallNumberOfRepetitions = read4digits();
23262428

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

2330-
repeatRegisterReadForDeviceAndAddress( menuTargetSensor /*warpSensorDevice*/,
2432+
for (int i = 0; i < overallNumberOfRepetitions; i++)
2433+
{
2434+
repeatRegisterReadForDeviceAndAddress( menuTargetSensor /*warpSensorDevice*/,
23312435
menuRegisterAddress /*baseAddress */,
23322436
menuI2cPullupEnable,
23332437
autoIncrement /*autoIncrement*/,
@@ -2339,6 +2443,7 @@ main(void)
23392443
adaptiveSssupplyMaxMillivolts,
23402444
referenceByte
23412445
);
2446+
}
23422447

23432448
break;
23442449
}
@@ -3572,4 +3677,4 @@ activateAllLowPowerSensorModes(void)
35723677
* For now, simply hold its reset line low.
35733678
*/
35743679
GPIO_DRV_ClearPinOutput(kWarpPinADXL362_CS_PAN1326_nSHUTD);
3575-
}
3680+
}

0 commit comments

Comments
 (0)