EFM32 Jade Gecko 12 Software Documentation  efm32jg12-doc-5.1.2
ccs811.c
Go to the documentation of this file.
1 /***************************************************************************/
17 #include <stddef.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdarg.h>
21 
22 #include "i2cspm.h"
23 
24 #include "thunderboard/board.h"
25 #include "thunderboard/ccs811.h"
26 #include "thunderboard/util.h"
27 
28 #include "thunderboard/rfs/rfs.h"
29 
30  /**************************************************************************/
37 /***************************************************************************/
45 #if (CCS811_FIRMWARE_UPDATE>0)
46  #pragma message("CCS811 firmware update included")
47  #include "ccs811_firmware.h"
48  static uint32_t CCS811_firmwareVerificationAndUpdate( void );
49 
50  static uint32_t CCS811_eraseApplication ( void );
51  static bool CCS811_verifyApplication ( void );
52 
53  static void debug_printf(const char *format, ...);
54 #endif
55 
56 static uint32_t CCS811_setAppStart ( void );
57 
60 /***************************************************************************/
67 uint32_t CCS811_init( void )
68 {
69 
70  uint8_t id;
71  uint32_t status;
72 
73  /* Enable the sensor and wake it up */
74  BOARD_gasSensorEnable( true );
75  BOARD_gasSensorWake( true );
76 
77  /* About 80 ms required to reliably start the device, wait a bit more */
78  UTIL_delay( 100 );
79 
80  /* Check if the chip present and working by reading the hardware ID */
81  status = CCS811_getHardwareID( &id );
82  if( ( status != CCS811_OK ) && ( id != CCS811_HW_ID ) ) {
84  }
85 
86  /* If enabled check the current firmware version and update it */
87  /* if there is a newer one available */
88 #if (CCS811_FIRMWARE_UPDATE>0)
89  status = CCS811_firmwareVerificationAndUpdate();
90 #endif
91 
92  /* Go back to sleep */
93  BOARD_gasSensorWake( false );
94 
95  return CCS811_OK;
96 
97 }
98 
99 /***************************************************************************/
106 uint32_t CCS811_deInit( void )
107 {
108 
109  /* Disable the sensor */
110  BOARD_gasSensorWake( false );
111  BOARD_gasSensorEnable( false );
112 
113  return CCS811_OK;
114 
115 }
116 
117 /***************************************************************************/
127 uint32_t CCS811_getHardwareID( uint8_t *hardwareID )
128 {
129 
130  uint32_t result;
131 
132  result = CCS811_readMailbox( CCS811_ADDR_HW_ID, 1, hardwareID );
133 
134  return result;
135 
136 }
137 
138  /**************************************************************************/
148 uint32_t CCS811_getStatus( uint8_t *status )
149 {
150 
151  uint32_t result;
152 
153  result = CCS811_readMailbox( CCS811_ADDR_STATUS, 1, status );
154 
155  return result;
156 
157 }
158 
159 /***************************************************************************/
167 {
168 
169  bool state;
170  uint32_t status;
171  uint8_t reg;
172 
173  state = false;
174  /* Read the status register */
175  status = CCS811_getStatus( &reg );
176 
177  /* Check if the DATA_READY bit is set */
178  if( ( status == CCS811_OK ) && ( ( reg & 0x08 ) == 0x08 ) ) {
179  state = true;
180  }
181 
182  return state;
183 
184 }
185 
186 /***************************************************************************/
194 {
195 
196  uint8_t buffer[8];
197 
199  printf( "STATUS : %02X\r\n", buffer[0] );
200 
202  printf( "MEASURE_MODE : %02X\r\n", buffer[0] );
203 
205  printf( "ALG_DATA : %02X%02X %02X%02X\r\n", buffer[0], buffer[1], buffer[2], buffer[3] );
206 
208  printf( "RAW_DATA : %02X%02X\r\n", buffer[0], buffer[1] );
209 
211  printf( "ENV_DATA : %02X%02X %02X%02X\r\n", buffer[0], buffer[1], buffer[2], buffer[3] );
212 
213  CCS811_readMailbox( CCS811_ADDR_NTC, 4, buffer );
214  printf( "NTC : %02X%02X %02X%02X\r\n", buffer[0], buffer[1], buffer[2], buffer[3] );
215 
217  printf( "THRESHOLDS : %02X%02X %02X%02X\r\n", buffer[0], buffer[1], buffer[2], buffer[3] );
218 
220  printf( "HW_ID : %02X\r\n", buffer[0] );
221 
223  printf( "HW_VERSION : %02X\r\n", buffer[0] );
224 
226  printf( "BOOT_VERSION : %d.%d.%d\r\n", ( buffer[0] >> 4 ) & 0xF, buffer[0] & 0xF, buffer[1] );
227 
229  printf( "APP_VERSION : %d.%d.%d\r\n", ( buffer[0] >> 4 ) & 0xF, buffer[0] & 0xF, buffer[1] );
230 
232  printf( "ERR_ID : %02X\r\n", buffer[0] );
233 
234  return;
235 
236 }
237 
238 /***************************************************************************/
245 uint32_t CCS811_startApplication( void )
246 {
247 
248  uint32_t result;
249  uint8_t status;
250 
251  /* Read status */
252  result = CCS811_readMailbox( CCS811_ADDR_STATUS, 1, &status );
253 
254  /* If no application firmware present in the CCS811 then return an error message */
255  if( ( status & 0x10 ) != 0x10 ) {
257  }
258 
259  /* Issue APP_START */
260  result += CCS811_setAppStart();
261 
262  /* Check status again */
263  result = CCS811_readMailbox( CCS811_ADDR_STATUS, 1, &status );
264 
265  /* If the chip firmware did not switch to application mode then return with error */
266  if( ( status & 0x90 ) != 0x90 ) {
268  }
269 
270  return result;
271 
272 }
273 
274 /***************************************************************************/
290 uint32_t CCS811_readMailbox( uint8_t id, uint8_t length, uint8_t *data )
291 {
292 
295  uint8_t i2c_write_data[1];
296  uint32_t retval;
297 
298  retval = CCS811_OK;
299 
300  BOARD_gasSensorWake( true );
301 
302  /* Write data */
303  i2c_write_data[0] = id;
304 
305  /* Configure I2C bus transaction */
308  seq.buf[0].data = i2c_write_data;
309  seq.buf[0].len = 1;
310 
311  /* Select length of data to be read */
312  seq.buf[1].data = data;
313  seq.buf[1].len = length;
314 
315  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
316  if( ret != i2cTransferDone ) {
318  }
319 
320  BOARD_gasSensorWake( false );
321 
322  return retval;
323 
324 }
325 
326 /***************************************************************************/
339 uint32_t CCS811_getMeasurement( uint16_t *eco2, uint16_t *tvoc )
340 {
341 
344  uint8_t i2c_read_data[4];
345  uint8_t i2c_write_data[1];
346  uint32_t retval;
347 
348  retval = CCS811_OK;
349 
350  *eco2 = 0;
351  *tvoc = 0;
352 
353  BOARD_gasSensorWake( true );
354 
355  /* Read four bytes from the ALG_RESULT_DATA mailbox register */
356  i2c_write_data[0] = CCS811_ADDR_ALG_RESULT_DATA;
357 
360  seq.buf[0].data = i2c_write_data;
361  seq.buf[0].len = 1;
362  seq.buf[1].data = i2c_read_data;
363  seq.buf[1].len = 4;
364 
365  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
366  if( ret != i2cTransferDone ) {
368  } else {
369  /* Convert the read bytes to 16 bit values */
370  *eco2 = ( (uint16_t) i2c_read_data[0] << 8 ) + (uint16_t) i2c_read_data[1];
371  *tvoc = ( (uint16_t) i2c_read_data[2] << 8 ) + (uint16_t) i2c_read_data[3];
372  }
373 
374  BOARD_gasSensorWake( false );
375 
376  return retval;
377 
378 }
379 
380 /***************************************************************************/
394 uint32_t CCS811_getRawData( uint16_t *current, uint16_t *rawData )
395 {
396 
399  uint8_t i2c_read_data[2];
400  uint8_t i2c_write_data[1];
401  uint32_t retval;
402 
403  retval = CCS811_OK;
404 
405  *current = 0;
406  *rawData = 0;
407 
408  BOARD_gasSensorWake( true );
409 
410  /* Read four bytes from the CCS811_ADDR_RAW_DATA mailbox register */
411  i2c_write_data[0] = CCS811_ADDR_RAW_DATA;
412 
415  seq.buf[0].data = i2c_write_data;
416  seq.buf[0].len = 1;
417  seq.buf[1].data = i2c_read_data;
418  seq.buf[1].len = 2;
419 
420  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
421  if( ret != i2cTransferDone ) {
423  } else {
424  /* current: the upper six bits of Byte0 */
425  *current = (uint16_t) ( ( i2c_read_data[0] >> 2 ) & 0x3F );
426  /* raw ADC reading: the lower two bits of Byte0 is the MSB, Byte1 is the LSB */
427  *rawData = (uint16_t) ( ( i2c_read_data[0] & 0x03 ) << 8 ) + (uint16_t) i2c_read_data[1];
428  }
429 
430  BOARD_gasSensorWake( false );
431 
432  return retval;
433 
434 }
435 
436 /***************************************************************************/
443 uint32_t CCS811_softwareReset( void )
444 {
445 
448  uint8_t i2c_read_data[4];
449  uint8_t i2c_write_data[5];
450  uint32_t retval;
451 
452  retval = CCS811_OK;
453 
454  BOARD_gasSensorWake( true );
455 
456  /* Write the 0x11 0xE5 0x72 0x8A key sequence to software reset register */
457  /* The key sequence is used to prevent accidental reset */
458  i2c_write_data[0] = CCS811_ADDR_SW_RESET;
459  i2c_write_data[1] = 0x11;
460  i2c_write_data[2] = 0xE5;
461  i2c_write_data[3] = 0x72;
462  i2c_write_data[4] = 0x8A;
463 
465  seq.flags = I2C_FLAG_WRITE;
466  seq.buf[0].data = i2c_write_data;
467  seq.buf[0].len = 5;
468  seq.buf[1].data = i2c_read_data;
469  seq.buf[1].len = 0;
470 
471  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
472  if( ret != i2cTransferDone ) {
474  }
475 
476  BOARD_gasSensorWake( false );
477 
478  return retval;
479 
480 }
481 
482 /***************************************************************************/
492 uint32_t CCS811_setMeasureMode( uint8_t measMode )
493 {
494 
497  uint8_t i2c_read_data[1];
498  uint8_t i2c_write_data[2];
499  uint32_t retval;
500 
501  retval = CCS811_OK;
502 
503  BOARD_gasSensorWake( true );
504 
505  /* Bits 7,6,2,1 and 0 are reserved, clear them */
506  measMode = ( measMode & 0x38 );
507 
508  /* Write to the measurement mode register */
509  i2c_write_data[0] = CCS811_ADDR_MEASURE_MODE;
510  i2c_write_data[1] = measMode;
511 
513  seq.flags = I2C_FLAG_WRITE;
514  seq.buf[0].data = i2c_write_data;
515  seq.buf[0].len = 2;
516  seq.buf[1].data = i2c_read_data;
517  seq.buf[1].len = 0;
518 
519  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
520  if( ret != i2cTransferDone ) {
522  }
523 
524  BOARD_gasSensorWake( false );
525 
526  return retval;
527 
528 }
529 
532 /***************************************************************************/
539 static uint32_t CCS811_setAppStart( void )
540 {
541 
544  uint8_t i2c_read_data[2];
545  uint8_t i2c_write_data[1];
546  uint32_t retval;
547 
548  retval = CCS811_OK;
549 
550  BOARD_gasSensorWake( true );
551 
552  /* Perform a write with no data to the APP_START register to change the */
553  /* state from boot mode to application mode */
554  i2c_write_data[0] = CCS811_ADDR_APP_START;
555 
557  seq.flags = I2C_FLAG_WRITE;
558  seq.buf[0].data = i2c_write_data;
559  seq.buf[0].len = 1;
560  seq.buf[1].data = i2c_read_data;
561  seq.buf[1].len = 0;
562 
563  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
564  if( ret != i2cTransferDone ) {
566  }
567 
568  BOARD_gasSensorWake( false );
569 
570  return retval;
571 
572 }
573 
574 #if (CCS811_FIRMWARE_UPDATE>0)
575 
576 /***************************************************************************/
583 static uint32_t CCS811_eraseApplication( void )
584 {
585 
588  uint8_t i2c_read_data[4];
589  uint8_t i2c_write_data[5];
590  uint32_t retval;
591 
592  retval = CCS811_OK;
593 
594  BOARD_gasSensorWake( true );
595 
596  /* Write the 0xE7 0xA7 0xE6 0x09 key sequence to firmware erase register */
597  /* The key sequence is used to prevent accidental erase */
598  i2c_write_data[0] = CCS811_ADDR_FW_ERASE;
599  i2c_write_data[1] = 0xE7;
600  i2c_write_data[2] = 0xA7;
601  i2c_write_data[3] = 0xE6;
602  i2c_write_data[4] = 0x09;
603 
605  seq.flags = I2C_FLAG_WRITE;
606  seq.buf[0].data = i2c_write_data;
607  seq.buf[0].len = 5;
608  seq.buf[1].data = i2c_read_data;
609  seq.buf[1].len = 0;
610 
611  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
612  if( ret != i2cTransferDone ) {
614  }
615 
616  BOARD_gasSensorWake( false );
617 
618  return retval;
619 
620 }
621 
622 /***************************************************************************/
632 static uint32_t CCS811_programFirmware( uint8_t buffer[] )
633 {
634 
637  uint8_t i2c_read_data[2];
638  uint8_t i2c_write_data[9];
639  uint32_t retval;
640 
641  retval = CCS811_OK;
642 
643  BOARD_gasSensorWake( true );
644 
645  /* Send the Write Data to FLASH command and 8 bytes of binary program code */
646  i2c_write_data[0] = CCS811_ADDR_FW_PROGRAM;
647  i2c_write_data[1] = buffer[0];
648  i2c_write_data[2] = buffer[1];
649  i2c_write_data[3] = buffer[2];
650  i2c_write_data[4] = buffer[3];
651  i2c_write_data[5] = buffer[4];
652  i2c_write_data[6] = buffer[5];
653  i2c_write_data[7] = buffer[6];
654  i2c_write_data[8] = buffer[7];
655 
657  seq.flags = I2C_FLAG_WRITE;
658  seq.buf[0].data = i2c_write_data;
659  seq.buf[0].len = 9;
660  seq.buf[1].data = i2c_read_data;
661  seq.buf[1].len = 0;
662 
663  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
664  if( ret != i2cTransferDone ) {
666  }
667 
668  BOARD_gasSensorWake( false );
669 
670  return retval;
671 
672 }
673 
674 /***************************************************************************/
682 static bool CCS811_verifyApplication( void )
683 {
684 
685  uint32_t status;
686  uint8_t reg;
689  uint8_t i2c_read_data[2];
690  uint8_t i2c_write_data[2];
691  bool retval;
692 
693  retval = true;
694 
695  BOARD_gasSensorWake( true );
696 
697  /* Write (with no data) to the verify register to check if the firmware */
698  /* programmed to the CCS811 was received error free */
699  i2c_write_data[0] = CCS811_ADDR_FW_VERIFY;
700 
702  seq.flags = I2C_FLAG_WRITE;
703  seq.buf[0].data = i2c_write_data;
704  seq.buf[0].len = 1;
705  seq.buf[1].data = i2c_read_data;
706  seq.buf[1].len = 0;
707 
708  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
709  if( ret != i2cTransferDone ) {
710  retval = false;
711  } else {
712  /* Wait until the Verify command finishes */
713  UTIL_delay( 100 );
714  /* Check the status register to see if there were no errors */
715  status = CCS811_getStatus( &reg );
716  if( ( status == CCS811_OK ) && ( ( reg & 0x10 ) == 0x00 ) ) {
717  retval = false;
718  }
719  }
720 
721  BOARD_gasSensorWake( false );
722 
723  return retval;
724 
725 }
726 
727 /***************************************************************************/
736 static uint32_t CCS811_firmwareVerificationAndUpdate( void )
737 {
738 
739  uint8_t *fileName;
740  RFS_FileHandle fh;
741 
742  uint32_t status;
743  uint8_t reg;
744  uint8_t buffer[8];
745  uint8_t major, minor, patch;
746  int fmajor, fminor, fpatch;
747  int fileLength;
748  char vStr[3 + 1 + 3 + 1 + 3];
749  int i, n;
750  int pi, pus;
751  bool upgrade;
752 
753  /*************************************************************************/
755  /*************************************************************************/
757  major = ( buffer[0] >> 4 ) & 0xF;
758  minor = buffer[0] & 0xF;
759  patch = buffer[1];
760  debug_printf( "BOOT_VERSION : %d.%d.%d\r\n", major, minor, patch );
761 
763  major = ( buffer[0] >> 4 ) & 0xF;
764  minor = buffer[0] & 0xF;
765  patch = buffer[1];
766  debug_printf( "APP_VERSION : %d.%d.%d\r\n", major, minor, patch );
767 
768  fileName = RFS_getFileNameByIndex( 0 );
769  if( !RFS_fileOpen( &fh, fileName ) ) {
770  debug_printf( "RFS file open failed!\r\n" );
772  }
773  fileLength = RFS_getFileLength( &fh );
774 
775  debug_printf( "RFS file : %s [%d]\r\n", (char *) fileName, fileLength );
776  if( ( fileLength % 8 ) != 0 ) {
777  debug_printf( "RFS file not 8 byte multiple!\r\n" );
779  }
780 
781  /*************************************************************************/
783  /*************************************************************************/
784  for( i = 0; i < strlen( (char const *) fileName ); i++ ) {
785  if( fileName[i] == '_' ) {
786  pus = i + 1;
787  }
788  if( fileName[i] == '.' ) {
789  pi = i - 1;
790  break;
791  }
792  }
793 
794  /* Version substring copy */
795  memset( vStr, 0, sizeof( vStr ) );
796  for( i = pus; i <= pi; i++ ) {
797  vStr[i - pus] = fileName[i];
798  }
799 
800  n = sscanf( vStr, "%dv%dp%d", &fmajor, &fminor, &fpatch );
801  if( n != 3 ) {
803  }
804 
805  /* Check versioning */
806  upgrade = (fmajor > major) ||
807  ((fmajor == major) && (fminor > minor)) ||
808  ((fmajor == major) && (fminor == minor) && (fpatch > patch));
809 
810  /* Check for invalid version */
811  if( ( major == 0xf ) && ( minor == 0xf ) && ( patch == 0xff ) ) {
812  upgrade = true;
813  }
814 
815  if( !upgrade ) {
816  return CCS811_OK;
817  }
818 
819  /*************************************************************************/
821  /*************************************************************************/
822  status = CCS811_getStatus( &reg );
823  if( ( reg & 0x80 ) == 0x80 ) {
824 
825  /* In APP mode - Go to BOOT mode */
826 
827  status = CCS811_softwareReset();
828  if( ( status & 0x80 ) != 0x00 ) {
830  }
831 
832  UTIL_delay( 100 );
833 
834  /* Check for BOOT mode */
835  status = CCS811_getStatus( &reg );
836  if( ( reg & 0x80 ) != 0x00 ) {
838  }
839 
840  }
841 
842  /*************************************************************************/
844  /*************************************************************************/
845  status = CCS811_getStatus( &reg );
846  if( ( reg & 0x10 ) == 0x10 ) {
847 
848  /* Valid application - Erase this */
849 
850  status = CCS811_eraseApplication();
851  UTIL_delay( 500 );
852  if( ( status & 0x10 ) != 0x00 ) {
854  }
855 
856  UTIL_delay( 100 );
857 
858  /* Check APP_VALID flag again */
859  status = CCS811_getStatus( &reg );
860  if( ( reg & 0x10 ) != 0x00 ) {
862  }
863 
864  }
865 
866  /*************************************************************************/
868  /*************************************************************************/
869  for( i = 0; i < fileLength; i += 8 ) {
870 
871  /* Read the next 8 bytes from the binary firmware file */
872  n = RFS_fileRead( buffer, 1, 8, &fh );
873  debug_printf( "FW prog [%d] : %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
874  i / 8,
875  buffer[0], buffer[1], buffer[2], buffer[3],
876  buffer[4], buffer[5], buffer[6], buffer[7]
877  );
878  if( n != 1 ) {
880  }
881 
882  /* Write 8 bytes to the device's flash memory */
883  status = CCS811_programFirmware( buffer );
884  if( status != CCS811_OK ) {
885  debug_printf( " FAIL! \r\n" );
887  }
888  else {
889  debug_printf( " OK \r\n" );
890  }
891  }
892 
893  /*************************************************************************/
895  /*************************************************************************/
896  if( CCS811_verifyApplication() == false ) {
897  return false;
898  }
899 
900  /*************************************************************************/
902  /*************************************************************************/
903  debug_printf( "Cycling CCS811 power domain..." );
904  BOARD_gasSensorEnable( false );
905  UTIL_delay( 200 );
906  BOARD_gasSensorEnable( true );
907  UTIL_delay( 200 );
908  debug_printf( "OK\r\n" );
909 
910  return true;
911 
912 }
913 
914 static void debug_printf( const char *format, ... )
915 {
916 
917 #ifdef DEBUG
918  va_list args;
919  va_start(args, format);
920  vprintf(format, args);
921  va_end(args);
922 #endif
923 }
924 
925 #endif
926 
929 /***************************************************************************/
942 uint32_t CCS811_setEnvData( int32_t tempData, uint32_t rhData )
943 {
944 
947  uint8_t i2c_read_data[4];
948  uint8_t i2c_write_data[5];
949  uint8_t humidityRegValue;
950  uint8_t temperatureRegValue;
951  uint32_t retval;
952 
953  retval = CCS811_OK;
954 
955  BOARD_gasSensorWake( true );
956 
957  /* The CCS811 currently supports only 0.5% resolution */
958  /* If the fraction greater than 0.7 then round up the value */
959  /* Shift to the left by one to meet the required data format */
960  if( ( ( rhData % 1000 ) / 100 ) > 7 ) {
961  humidityRegValue = ( rhData / 1000 + 1 ) << 1;
962  }
963  else {
964  humidityRegValue = ( rhData / 1000 ) << 1;
965  }
966 
967  /* If the fraction is greater than 0.2 or less than 0.8 set the */
968  /* LSB bit, which is the most significant bit of the fraction 2^(-1) = 0.5 */
969  if( ( ( rhData % 1000 ) / 100 ) > 2 && ( ( ( rhData % 1000 ) / 100 ) < 8 ) ) {
970  humidityRegValue |= 0x01;
971  }
972 
973  /* Add +25 C to the temperature value */
974  /* The CCS811 currently supports only 0.5C resolution */
975  /* If the fraction greater than 0.7 then round up the value */
976  /* Shift to the left by one to meet the required data format */
977  tempData += 25000;
978  if( ( ( tempData % 1000 ) / 100 ) > 7 ) {
979  temperatureRegValue = ( tempData / 1000 + 1 ) << 1;
980  }
981  else {
982  temperatureRegValue = ( tempData / 1000 ) << 1;
983  }
984 
985  /* If the fraction is greater than 0.2 or less than 0.8 set the */
986  /* LSB bit, which is the most significant bit of the fraction 2^(-1) = 0.5 */
987  if( ( ( tempData % 1000 ) / 100 ) > 2 && ( ( ( tempData % 1000 ) / 100 ) < 8 ) ) {
988  temperatureRegValue |= 0x01;
989  }
990 
991  /* Write the correctly formatted values to the environmental data register */
992  /* The LSB bytes of the humidity and temperature data are 0x00 because */
993  /* the current CCS811 supports only 0.5% and 0.5C resolution */
994  i2c_write_data[0] = CCS811_ADDR_ENV_DATA;
995  i2c_write_data[1] = humidityRegValue;
996  i2c_write_data[2] = 0x00;
997  i2c_write_data[3] = temperatureRegValue;
998  i2c_write_data[4] = 0x00;
999 
1001  seq.flags = I2C_FLAG_WRITE;
1002  seq.buf[0].data = i2c_write_data;
1003  seq.buf[0].len = 5;
1004  seq.buf[1].data = i2c_read_data;
1005  seq.buf[1].len = 0;
1006 
1007  ret = I2CSPM_Transfer( CCS811_I2C_DEVICE, &seq );
1008  if( ret != i2cTransferDone ) {
1010  }
1011 
1012  BOARD_gasSensorWake( false );
1013 
1014  return retval;
1015 
1016 }
#define CCS811_ADDR_APP_START
Definition: ccs811.h:96
uint32_t CCS811_setMeasureMode(uint8_t measMode)
Sets the measurement mode of the CSS811 sensor.
Definition: ccs811.c:492
uint32_t BOARD_gasSensorWake(bool wake)
Wakes up the Air Quality / Gas Sensor.
Definition: board.c:583
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Perform I2C transfer.
Definition: i2cspm.c:124
#define CCS811_I2C_DEVICE_BUS_ADDRESS
Definition: ccs811.h:53
uint32_t CCS811_setEnvData(int32_t tempData, uint32_t rhData)
Writes temperature and humidity values to the environmental data regs.
Definition: ccs811.c:942
bool CCS811_isDataAvailable(void)
Checks if new measurement data available.
Definition: ccs811.c:166
Driver for the Cambridge CMOS Sensors CCS811 gas and indoor air quality sensor.
#define CCS811_ERROR_FIRMWARE_UPDATE_FAILED
Definition: ccs811.h:71
#define CCS811_ADDR_HW_VERSION
Definition: ccs811.h:89
void UTIL_delay(uint32_t ms)
Delays number of msTick Systicks (1 ms)
Definition: util.c:97
uint32_t CCS811_getStatus(uint8_t *status)
Reads the status of the CSS811 sensor.
Definition: ccs811.c:148
uint32_t CCS811_init(void)
Initializes the chip and performs firmware upgrade if required.
Definition: ccs811.c:67
#define CCS811_ADDR_SW_RESET
Definition: ccs811.h:97
#define CCS811_ERROR_NOT_IN_APPLICATION_MODE
Definition: ccs811.h:67
uint32_t CCS811_softwareReset(void)
Performs software reset on the CCS811.
Definition: ccs811.c:443
#define I2C_FLAG_WRITE
Indicate plain write sequence: S+ADDR(W)+DATA0+P.
Definition: em_i2c.h:124
I2C_TransferReturn_TypeDef
Definition: em_i2c.h:179
#define CCS811_ERROR_INIT_FAILED
Definition: ccs811.h:70
#define CCS811_ERROR_I2C_TRANSACTION_FAILED
Definition: ccs811.h:69
ROM File System Drive.
#define CCS811_ADDR_ENV_DATA
Definition: ccs811.h:85
uint32_t CCS811_getHardwareID(uint8_t *hardwareID)
Reads Hardware ID from the CSS811 sensor.
Definition: ccs811.c:127
#define CCS811_ADDR_FW_ERASE
Definition: ccs811.h:93
uint32_t CCS811_startApplication(void)
Switches the CSS811 chip from boot to application mode.
Definition: ccs811.c:245
I2C simple poll-based master mode driver for the DK/STK.
#define CCS811_ADDR_ERR_ID
Definition: ccs811.h:92
Utility Functions for the Thunderboard Sense.
struct I2C_TransferSeq_TypeDef::@0 buf[2]
#define CCS811_ADDR_STATUS
Definition: ccs811.h:81
#define CCS811_ERROR_APPLICATION_NOT_PRESENT
Definition: ccs811.h:66
uint32_t CCS811_getMeasurement(uint16_t *eco2, uint16_t *tvoc)
Reads measurement data (eCO2 and TVOC) from the CSS811 sensor.
Definition: ccs811.c:339
#define CCS811_HW_ID
Definition: ccs811.h:55
#define CCS811_ADDR_MEASURE_MODE
Definition: ccs811.h:82
uint32_t CCS811_readMailbox(uint8_t id, uint8_t length, uint8_t *data)
Reads data from a specific Mailbox address.
Definition: ccs811.c:290
#define CCS811_ADDR_THRESHOLDS
Definition: ccs811.h:87
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
Definition: em_i2c.h:252
#define CCS811_ADDR_FW_PROGRAM
Definition: ccs811.h:94
#define CCS811_ADDR_HW_ID
Definition: ccs811.h:88
#define CCS811_ADDR_RAW_DATA
Definition: ccs811.h:84
#define CCS811_ADDR_ALG_RESULT_DATA
Definition: ccs811.h:83
#define CCS811_ADDR_FW_BOOT_VERSION
Definition: ccs811.h:90
#define CCS811_OK
Definition: ccs811.h:65
#define I2C_FLAG_WRITE_READ
Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
Definition: em_i2c.h:148
#define CCS811_ADDR_NTC
Definition: ccs811.h:86
uint32_t CCS811_getRawData(uint16_t *current, uint16_t *rawData)
Gets the latest readings from the sense resistor of the CSS811 sensor.
Definition: ccs811.c:394
uint32_t CCS811_deInit(void)
De-initializes the chip.
Definition: ccs811.c:106
#define CCS811_ADDR_FW_APP_VERSION
Definition: ccs811.h:91
#define CCS811_ADDR_FW_VERIFY
Definition: ccs811.h:95
void CCS811_dumpRegisters(void)
Dumps the registers of the CSS811.
Definition: ccs811.c:193
uint16_t addr
Address to use after (repeated) start.
Definition: em_i2c.h:262
BOARD module header file.
#define CCS811_I2C_DEVICE
Definition: ccs811.h:52
uint32_t BOARD_gasSensorEnable(bool enable)
Enables or disables the Air Quality / Gas Sensor.
Definition: board.c:557