astek
GPS_I2C.h@0:f4c7ece483fe, 2019-12-27 (annotated)
- Committer:
- RoddyRod
- Date:
- Fri Dec 27 15:32:37 2019 +0000
- Revision:
- 0:f4c7ece483fe
fsabatier;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RoddyRod | 0:f4c7ece483fe | 1 | #ifndef __GPSI2C__ |
RoddyRod | 0:f4c7ece483fe | 2 | #define __GPSI2C__ |
RoddyRod | 0:f4c7ece483fe | 3 | |
RoddyRod | 0:f4c7ece483fe | 4 | #include "mbed.h" |
RoddyRod | 0:f4c7ece483fe | 5 | #include <string> |
RoddyRod | 0:f4c7ece483fe | 6 | |
RoddyRod | 0:f4c7ece483fe | 7 | #define MT333x_ADDR 0x10 //7-bit unshifted default I2C Address |
RoddyRod | 0:f4c7ece483fe | 8 | |
RoddyRod | 0:f4c7ece483fe | 9 | #define MAX_PACKET_SIZE 255 |
RoddyRod | 0:f4c7ece483fe | 10 | //If packet size is ever more than 255 the head and tail variables will need to be |
RoddyRod | 0:f4c7ece483fe | 11 | //changed to something other than uint8_t |
RoddyRod | 0:f4c7ece483fe | 12 | |
RoddyRod | 0:f4c7ece483fe | 13 | #define I2C_SPEED_STANDARD 100000 |
RoddyRod | 0:f4c7ece483fe | 14 | #define I2C_SPEED_FAST 400000 |
RoddyRod | 0:f4c7ece483fe | 15 | |
RoddyRod | 0:f4c7ece483fe | 16 | class GPS_I2C{ |
RoddyRod | 0:f4c7ece483fe | 17 | public: |
RoddyRod | 0:f4c7ece483fe | 18 | //Constructor |
RoddyRod | 0:f4c7ece483fe | 19 | GPS_I2C(PinName sda, PinName scl, uint32_t freq); //Init I2C interface with Pin and frequency |
RoddyRod | 0:f4c7ece483fe | 20 | ~GPS_I2C(); |
RoddyRod | 0:f4c7ece483fe | 21 | //Methods |
RoddyRod | 0:f4c7ece483fe | 22 | bool begin(); //Test if sensor is available |
RoddyRod | 0:f4c7ece483fe | 23 | void check(); |
RoddyRod | 0:f4c7ece483fe | 24 | uint8_t available(); |
RoddyRod | 0:f4c7ece483fe | 25 | uint8_t read(); |
RoddyRod | 0:f4c7ece483fe | 26 | //Variables |
RoddyRod | 0:f4c7ece483fe | 27 | uint8_t gpsData[MAX_PACKET_SIZE]; //The place to store valid incoming gps data |
RoddyRod | 0:f4c7ece483fe | 28 | |
RoddyRod | 0:f4c7ece483fe | 29 | private: |
RoddyRod | 0:f4c7ece483fe | 30 | /*I2C config*/ |
RoddyRod | 0:f4c7ece483fe | 31 | I2C _i2c; |
RoddyRod | 0:f4c7ece483fe | 32 | uint32_t _freq; |
RoddyRod | 0:f4c7ece483fe | 33 | |
RoddyRod | 0:f4c7ece483fe | 34 | /*GPS buffer beginning/ending*/ |
RoddyRod | 0:f4c7ece483fe | 35 | uint8_t _head; |
RoddyRod | 0:f4c7ece483fe | 36 | uint8_t _tail; |
RoddyRod | 0:f4c7ece483fe | 37 | }; |
RoddyRod | 0:f4c7ece483fe | 38 | |
RoddyRod | 0:f4c7ece483fe | 39 | #endif |