Chris Styles
/
EA_LEDS
Using the I2C LED driver on the Embedded Artists baseboard to control the LEDS.
PCA9532.h@0:5d07670e5b83, 2010-03-02 (annotated)
- Committer:
- chris
- Date:
- Tue Mar 02 07:40:02 2010 +0000
- Revision:
- 0:5d07670e5b83
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:5d07670e5b83 | 1 | /* PCA9532 |
chris | 0:5d07670e5b83 | 2 | * (c) 2009, cstyles |
chris | 0:5d07670e5b83 | 3 | */ |
chris | 0:5d07670e5b83 | 4 | |
chris | 0:5d07670e5b83 | 5 | #ifndef PCA9532_H |
chris | 0:5d07670e5b83 | 6 | #define PCA9532_H |
chris | 0:5d07670e5b83 | 7 | |
chris | 0:5d07670e5b83 | 8 | #include "mbed.h" |
chris | 0:5d07670e5b83 | 9 | |
chris | 0:5d07670e5b83 | 10 | // register names |
chris | 0:5d07670e5b83 | 11 | #define PCA9532_REG_INPUT0 0 |
chris | 0:5d07670e5b83 | 12 | #define PCA9532_REG_INPUT1 1 |
chris | 0:5d07670e5b83 | 13 | #define PCA9532_REG_PSC0 2 |
chris | 0:5d07670e5b83 | 14 | #define PCA9532_REG_PWM0 3 |
chris | 0:5d07670e5b83 | 15 | #define PCA9532_REG_PSC1 4 |
chris | 0:5d07670e5b83 | 16 | #define PCA9532_REG_PWM1 5 |
chris | 0:5d07670e5b83 | 17 | #define PCA9532_REG_LS0 6 |
chris | 0:5d07670e5b83 | 18 | #define PCA9532_REG_LS1 7 |
chris | 0:5d07670e5b83 | 19 | #define PCA9532_REG_LS2 8 |
chris | 0:5d07670e5b83 | 20 | #define PCA9532_REG_LS3 9 |
chris | 0:5d07670e5b83 | 21 | |
chris | 0:5d07670e5b83 | 22 | #define PCA9532_MODE_CLEAR 0 |
chris | 0:5d07670e5b83 | 23 | #define PCA9532_MODE_SET 1 |
chris | 0:5d07670e5b83 | 24 | #define PCA9532_MODE_PWM0 2 |
chris | 0:5d07670e5b83 | 25 | #define PCA9532_MODE_PWM1 3 |
chris | 0:5d07670e5b83 | 26 | |
chris | 0:5d07670e5b83 | 27 | |
chris | 0:5d07670e5b83 | 28 | |
chris | 0:5d07670e5b83 | 29 | |
chris | 0:5d07670e5b83 | 30 | |
chris | 0:5d07670e5b83 | 31 | class PCA9532 { |
chris | 0:5d07670e5b83 | 32 | |
chris | 0:5d07670e5b83 | 33 | public: |
chris | 0:5d07670e5b83 | 34 | |
chris | 0:5d07670e5b83 | 35 | PCA9532(PinName sda, PinName scl, int addr); |
chris | 0:5d07670e5b83 | 36 | |
chris | 0:5d07670e5b83 | 37 | void write (int leds); |
chris | 0:5d07670e5b83 | 38 | |
chris | 0:5d07670e5b83 | 39 | void set (int leds); |
chris | 0:5d07670e5b83 | 40 | void clear (int leds); |
chris | 0:5d07670e5b83 | 41 | void pwm0 (int leds); |
chris | 0:5d07670e5b83 | 42 | void pwm1 (int leds); |
chris | 0:5d07670e5b83 | 43 | |
chris | 0:5d07670e5b83 | 44 | void duty0 (float d); |
chris | 0:5d07670e5b83 | 45 | void duty1 (float d); |
chris | 0:5d07670e5b83 | 46 | |
chris | 0:5d07670e5b83 | 47 | void period0 (float t); |
chris | 0:5d07670e5b83 | 48 | void period1 (float t); |
chris | 0:5d07670e5b83 | 49 | |
chris | 0:5d07670e5b83 | 50 | protected: |
chris | 0:5d07670e5b83 | 51 | |
chris | 0:5d07670e5b83 | 52 | void _write(int reg, int data); |
chris | 0:5d07670e5b83 | 53 | int _read(int reg); |
chris | 0:5d07670e5b83 | 54 | |
chris | 0:5d07670e5b83 | 55 | void _rmw(int led, int mode); |
chris | 0:5d07670e5b83 | 56 | |
chris | 0:5d07670e5b83 | 57 | int _addr; |
chris | 0:5d07670e5b83 | 58 | |
chris | 0:5d07670e5b83 | 59 | I2C _i2c; |
chris | 0:5d07670e5b83 | 60 | |
chris | 0:5d07670e5b83 | 61 | }; |
chris | 0:5d07670e5b83 | 62 | |
chris | 0:5d07670e5b83 | 63 | |
chris | 0:5d07670e5b83 | 64 | #endif |