fork of seeed studio 4-digit display for st nucleo board
Dependencies: Data_Clock_Pair Seeed_Chainable_LED Seeed_Four_Digit_Disp Seeed_IR_Temp_Sensor Seeed_Led_Bar
Fork of Seeed_Grove_4_Digit_Display_Clock by
SeeedQTouch.h@20:2e72ddd68cda, 2017-06-22 (annotated)
- Committer:
- tulanthoar
- Date:
- Thu Jun 22 12:17:29 2017 -0600
- Revision:
- 20:2e72ddd68cda
add q touch which doesn't work yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tulanthoar | 20:2e72ddd68cda | 1 | #ifndef MBED_SEEED_Q_TOUCH_H |
tulanthoar | 20:2e72ddd68cda | 2 | #define MBED_SEEED_Q_TOUCH_H |
tulanthoar | 20:2e72ddd68cda | 3 | #include "mbed.h" |
tulanthoar | 20:2e72ddd68cda | 4 | #include "DataClockPair.h" |
tulanthoar | 20:2e72ddd68cda | 5 | |
tulanthoar | 20:2e72ddd68cda | 6 | #define QTOUCH_REG_RESET 0X39 // reset |
tulanthoar | 20:2e72ddd68cda | 7 | class SeeedQTouch { |
tulanthoar | 20:2e72ddd68cda | 8 | |
tulanthoar | 20:2e72ddd68cda | 9 | static const int devAddr_ = 0x1b; |
tulanthoar | 20:2e72ddd68cda | 10 | int readOpCode_; |
tulanthoar | 20:2e72ddd68cda | 11 | int writeOpCode_; |
tulanthoar | 20:2e72ddd68cda | 12 | static const int stateReg_ = 0x03; |
tulanthoar | 20:2e72ddd68cda | 13 | static const int calibrateReg_ = 0x38; |
tulanthoar | 20:2e72ddd68cda | 14 | I2C i2c_; |
tulanthoar | 20:2e72ddd68cda | 15 | int read_register_(int address, Serial* pc); |
tulanthoar | 20:2e72ddd68cda | 16 | int read_state_(Serial* pc); |
tulanthoar | 20:2e72ddd68cda | 17 | public: |
tulanthoar | 20:2e72ddd68cda | 18 | SeeedQTouch(DataClockPair pins); |
tulanthoar | 20:2e72ddd68cda | 19 | int key_touch(Serial* pc); |
tulanthoar | 20:2e72ddd68cda | 20 | }; |
tulanthoar | 20:2e72ddd68cda | 21 | |
tulanthoar | 20:2e72ddd68cda | 22 | SeeedQTouch::SeeedQTouch(DataClockPair pins) : i2c_(pins.dataPin, pins.clockPin) { |
tulanthoar | 20:2e72ddd68cda | 23 | /* readOpCode_ = devAddr_ | 0x01; */ |
tulanthoar | 20:2e72ddd68cda | 24 | /* writeOpCode_ = devAddr_ & 0xFE; */ |
tulanthoar | 20:2e72ddd68cda | 25 | /* writeOpCode_ = devAddr_ | 0x00; */ |
tulanthoar | 20:2e72ddd68cda | 26 | readOpCode_ = devAddr_; |
tulanthoar | 20:2e72ddd68cda | 27 | writeOpCode_ = devAddr_; |
tulanthoar | 20:2e72ddd68cda | 28 | } |
tulanthoar | 20:2e72ddd68cda | 29 | |
tulanthoar | 20:2e72ddd68cda | 30 | int SeeedQTouch::read_register_(int address, Serial* pc) { |
tulanthoar | 20:2e72ddd68cda | 31 | int success; |
tulanthoar | 20:2e72ddd68cda | 32 | char dataWrite[2]; |
tulanthoar | 20:2e72ddd68cda | 33 | char resetWrite[2]; |
tulanthoar | 20:2e72ddd68cda | 34 | char dataRead[2]; |
tulanthoar | 20:2e72ddd68cda | 35 | dataWrite[0] = 0x00; |
tulanthoar | 20:2e72ddd68cda | 36 | dataWrite[1] = 0x55; |
tulanthoar | 20:2e72ddd68cda | 37 | resetWrite[0] = QTOUCH_REG_RESET; |
tulanthoar | 20:2e72ddd68cda | 38 | resetWrite[1] = 0x55; |
tulanthoar | 20:2e72ddd68cda | 39 | /* int success = i2c_.write(devAddr_, dataWrite, 1, 0); */ |
tulanthoar | 20:2e72ddd68cda | 40 | /* if( pc ) pc->printf("requesting register %i success is %i", dataWrite[0], success); */ |
tulanthoar | 20:2e72ddd68cda | 41 | /* dataWrite[0] = 0x55; */ |
tulanthoar | 20:2e72ddd68cda | 42 | success = i2c_.write(writeOpCode_, resetWrite, 2); |
tulanthoar | 20:2e72ddd68cda | 43 | success = i2c_.write(writeOpCode_, dataWrite, 2); |
tulanthoar | 20:2e72ddd68cda | 44 | if( pc ) pc->printf("requesting register %i success is %i", dataWrite[0], success); |
tulanthoar | 20:2e72ddd68cda | 45 | /* dataWrite[0] = stateReg_; */ |
tulanthoar | 20:2e72ddd68cda | 46 | /* wait_ms(1); */ |
tulanthoar | 20:2e72ddd68cda | 47 | /* i2c_.start(); */ |
tulanthoar | 20:2e72ddd68cda | 48 | /* wait_ms(1); */ |
tulanthoar | 20:2e72ddd68cda | 49 | /* success = i2c_.write(devAddr_, dataWrite, 1, 1); */ |
tulanthoar | 20:2e72ddd68cda | 50 | /* wait_ms(1); */ |
tulanthoar | 20:2e72ddd68cda | 51 | success = i2c_.read(readOpCode_, dataRead, 2); |
tulanthoar | 20:2e72ddd68cda | 52 | if( pc ) pc->printf("return value is %i or %i success is %i", dataRead[0] , dataRead[1], success); |
tulanthoar | 20:2e72ddd68cda | 53 | /* i2c_.stop(); */ |
tulanthoar | 20:2e72ddd68cda | 54 | wait_ms(1); |
tulanthoar | 20:2e72ddd68cda | 55 | /* int result; */ |
tulanthoar | 20:2e72ddd68cda | 56 | /* i2c_.start(); */ |
tulanthoar | 20:2e72ddd68cda | 57 | wait_ms(1); |
tulanthoar | 20:2e72ddd68cda | 58 | /* result = i2c_.read(1); */ |
tulanthoar | 20:2e72ddd68cda | 59 | wait_ms(1); |
tulanthoar | 20:2e72ddd68cda | 60 | /* i2c_.stop(); */ |
tulanthoar | 20:2e72ddd68cda | 61 | return dataRead[0]; |
tulanthoar | 20:2e72ddd68cda | 62 | } |
tulanthoar | 20:2e72ddd68cda | 63 | |
tulanthoar | 20:2e72ddd68cda | 64 | int SeeedQTouch::read_state_(Serial* pc) { |
tulanthoar | 20:2e72ddd68cda | 65 | return read_register_(0x03, pc); |
tulanthoar | 20:2e72ddd68cda | 66 | } |
tulanthoar | 20:2e72ddd68cda | 67 | |
tulanthoar | 20:2e72ddd68cda | 68 | int SeeedQTouch::key_touch(Serial* pc = 0) { |
tulanthoar | 20:2e72ddd68cda | 69 | int keys = read_state_(pc); |
tulanthoar | 20:2e72ddd68cda | 70 | return(keys); |
tulanthoar | 20:2e72ddd68cda | 71 | } |
tulanthoar | 20:2e72ddd68cda | 72 | #endif |