Register Display On Serial Terminal For Azoteq IQS622 Ultra Low Power (5uA) I2C Multi-Function Sensor with Light Sensor + Active (Reflective) IR + Touch + Hall Effect Sensor

Dependents:   IQS622_HelloWorld

A library that performs a register dump of the Azoteq IQS622 ultra low power multisensor registers.

More information on the IQS622 here:

Components / IQS622
Azoteq IQS622 ultra low power sensor for ambient light, active (reflective) IR, magnetic field, capacitance and inductive proximity. Empowers next-generation user interfaces.


Low Cost Evaluation Board for Azoteq IQS622 Ultra Low Power (5uA) I2C Multi-Function Sensor with Light Sensor, Active (Reflective) IR, Touch and Hall Effect Sensor


Committer:
AzqDev
Date:
Sat May 13 02:24:05 2017 +0000
Revision:
2:e8e0c85e8d9b
Parent:
1:20266bfaa709
Child:
3:fc73ce1a283a
Fixed Register Names

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzqDev 0:932376194edb 1 // A class library to display Azoteq IQS622 registers on a terminal
AzqDev 0:932376194edb 2
AzqDev 0:932376194edb 3 // Copyright 2017 Azoteq. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AzqDev 0:932376194edb 4
AzqDev 0:932376194edb 5 // More info on IQS622 sensor IC: http://bit.ly/IQS622-info
AzqDev 0:932376194edb 6
AzqDev 0:932376194edb 7 // IQS622 1-minute youtube video: N.A.
AzqDev 0:932376194edb 8
AzqDev 0:932376194edb 9 #include "IQS622DisplayTerminal.h"
AzqDev 0:932376194edb 10
AzqDev 0:932376194edb 11 // constructor
AzqDev 0:932376194edb 12 #if defined(TARGET_TEENSY3_1) || defined (TARGET_TEENSY3_2) || IQS_USE_USBSERIAL
AzqDev 0:932376194edb 13 IQS622Display::IQS622Display() : USBSerial() // use our own USB device stack
AzqDev 0:932376194edb 14 #else
AzqDev 0:932376194edb 15 IQS622Display::IQS622Display() : Serial(USBTX,USBRX) // use mbed default serial port
AzqDev 0:932376194edb 16 #endif
AzqDev 0:932376194edb 17
AzqDev 1:20266bfaa709 18 {
AzqDev 0:932376194edb 19 frameCounter=0;
AzqDev 0:932376194edb 20 baud(DISPLAY_BAUD_RATE);
AzqDev 1:20266bfaa709 21 }
AzqDev 0:932376194edb 22
AzqDev 0:932376194edb 23 #if defined(TARGET_TEENSY3_1) || defined (TARGET_TEENSY3_2) || IQS_USE_USBSERIAL
AzqDev 1:20266bfaa709 24 void IQS622Display::baud(int baudRate) {}
AzqDev 0:932376194edb 25 #endif
AzqDev 0:932376194edb 26
AzqDev 0:932376194edb 27 // display a startup message to serial port
AzqDev 1:20266bfaa709 28 void IQS622Display::helloMessage(bool waitForUser)
AzqDev 1:20266bfaa709 29 {
AzqDev 0:932376194edb 30 puts("\x1b[2J \x1b[?25l \x1b[H"); // ANSII/VT100 codes to clear screen, invisible cursor, home cursor
AzqDev 1:20266bfaa709 31 printf(" IQS622 Register Display\r\n\r\n");
AzqDev 0:932376194edb 32 printf("To get a smooth screen refresh effect, use a terminal program that supports ANSI/VT100 escape codes such as Tera Term.\r\n\r\n");
AzqDev 0:932376194edb 33 printf("Handy hint - In many terminal programs, Alt-B (break) will reset your mbed Board.\r\n\r\n");
AzqDev 0:932376194edb 34 printf("Press any key to continue...\r\n");
AzqDev 0:932376194edb 35 if ( waitForUser ) while( ! readable() ); // wait for keypress to continue
AzqDev 0:932376194edb 36 puts("\x1b[2J \x1b[?25l \x1b[H"); // ANSII/VT100 codes to clear screen, invisible cursor, home cursor
AzqDev 0:932376194edb 37 }
AzqDev 0:932376194edb 38
AzqDev 0:932376194edb 39 // show headings and I2C error count
AzqDev 1:20266bfaa709 40 void IQS622Display::showStatus(int I2Cspeed, int I2CErrorCount)
AzqDev 1:20266bfaa709 41 {
AzqDev 0:932376194edb 42 frameCounter++;
AzqDev 0:932376194edb 43 puts("\x1b[H"); // ANSI/VT100 command for cursor home
AzqDev 1:20266bfaa709 44 printf("\t");
AzqDev 0:932376194edb 45 printf("\t IQS622 Register Display\r\n\r\n"); // heading
AzqDev 0:932376194edb 46 printf("\t Frame number %06d", frameCounter);
AzqDev 0:932376194edb 47 printf("\t I2C Speed %dk", I2Cspeed/1000);
AzqDev 0:932376194edb 48 printf("\t I2C Errors %d", I2CErrorCount);
AzqDev 0:932376194edb 49 }
AzqDev 0:932376194edb 50
AzqDev 1:20266bfaa709 51 // dump one line of text from the buffer with VT100 color formatting
AzqDev 1:20266bfaa709 52 void IQS622Display::showLine(char * buffer, char * color, int startbyte, int endbyte)
AzqDev 1:20266bfaa709 53 {
AzqDev 1:20266bfaa709 54 for (int i=startbyte; i<=endbyte; i++) {
AzqDev 1:20266bfaa709 55 if ( color == NULL || color[i] == 0 )
AzqDev 1:20266bfaa709 56 printf("%02x ", buffer[i]);
AzqDev 1:20266bfaa709 57 else
AzqDev 1:20266bfaa709 58 #define USE_IQS_COLOR_DISPLAY
AzqDev 1:20266bfaa709 59 #ifndef DONT_USE_IQS_COLOR_DISPLAY
AzqDev 1:20266bfaa709 60 printf("\x1b[32m%02x\x1b[30m ", buffer[i]); // print out in green (ANSI VT100 code)
AzqDev 1:20266bfaa709 61 #else
AzqDev 1:20266bfaa709 62 printf("%02x ", buffer[i]); // print out in black & white
AzqDev 1:20266bfaa709 63 #endif
AzqDev 1:20266bfaa709 64 }
AzqDev 1:20266bfaa709 65 }
AzqDev 1:20266bfaa709 66
AzqDev 0:932376194edb 67 // formatted hex display of IQS622 registers
AzqDev 1:20266bfaa709 68 void IQS622Display::showRegisters(char * buffer,char * color)
AzqDev 1:20266bfaa709 69 {
AzqDev 1:20266bfaa709 70 printf("\r\n\r\n Device ID & Version (42) [00] "); showLine(buffer,color,0x00,0x02);
AzqDev 2:e8e0c85e8d9b 71 printf("\r\n\r\n Events and Flags [10] "); showLine(buffer,color,0x10,0x1b);
AzqDev 2:e8e0c85e8d9b 72 printf("\r\n\r\n Channel 0-6 Raw Values [20] "); showLine(buffer,color,0x20,0x2b);
AzqDev 2:e8e0c85e8d9b 73 printf("\r\n\r\n Long Term Average Data [30] "); showLine(buffer,color,0x30,0x35);
AzqDev 1:20266bfaa709 74 printf("\r\n\r\n Proxfusion Settings [40] "); showLine(buffer,color,0x40,0x4d);
AzqDev 2:e8e0c85e8d9b 75 printf("\r\n\r\n Proxfusion Thresholds [50] "); showLine(buffer,color,0x50,0x57);
AzqDev 2:e8e0c85e8d9b 76 printf("\r\n\r\n SAR Thresholds [60] "); showLine(buffer,color,0x60,0x66);
AzqDev 2:e8e0c85e8d9b 77 printf("\r\n\r\n Light/IR Sensor Settings [70] "); showLine(buffer,color,0x70,0x75);
AzqDev 2:e8e0c85e8d9b 78 printf("\r\n\r\n IR Threshold Settings [90] "); showLine(buffer,color,0x90,0x93);
AzqDev 2:e8e0c85e8d9b 79 printf("\r\n\r\n Hall Switch Thresholds [A0] "); showLine(buffer,color,0xa0,0xa3);
AzqDev 2:e8e0c85e8d9b 80 printf("\r\n\r\n Temperature Thresholds [B0] "); showLine(buffer,color,0xb0,0xb3);
AzqDev 2:e8e0c85e8d9b 81 printf("\r\n\r\n Device & Power Settings [D0] "); showLine(buffer,color,0xd0,0xd8);
AzqDev 0:932376194edb 82 printf("\r\n\r\n");
AzqDev 0:932376194edb 83 }