Chris Styles
/
EA_PCA9532_HelloWorld
Simple Hello World for the PCA9532 on the Embedded Artists Baseboard
PCA9532.h@1:bd3f6bfeebac, 2010-05-07 (annotated)
- Committer:
- chris
- Date:
- Fri May 07 12:40:00 2010 +0000
- Revision:
- 1:bd3f6bfeebac
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 1:bd3f6bfeebac | 1 | /* mbed PCF9532 LED Driver Library |
chris | 1:bd3f6bfeebac | 2 | * |
chris | 1:bd3f6bfeebac | 3 | * Copyright (c) 2010, cstyles (http://mbed.org) |
chris | 1:bd3f6bfeebac | 4 | * |
chris | 1:bd3f6bfeebac | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
chris | 1:bd3f6bfeebac | 6 | * of this software and associated documentation files (the "Software"), to deal |
chris | 1:bd3f6bfeebac | 7 | * in the Software without restriction, including without limitation the rights |
chris | 1:bd3f6bfeebac | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
chris | 1:bd3f6bfeebac | 9 | * copies of the Software, and to permit persons to whom the Software is |
chris | 1:bd3f6bfeebac | 10 | * furnished to do so, subject to the following conditions: |
chris | 1:bd3f6bfeebac | 11 | * |
chris | 1:bd3f6bfeebac | 12 | * The above copyright notice and this permission notice shall be included in |
chris | 1:bd3f6bfeebac | 13 | * all copies or substantial portions of the Software. |
chris | 1:bd3f6bfeebac | 14 | * |
chris | 1:bd3f6bfeebac | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
chris | 1:bd3f6bfeebac | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
chris | 1:bd3f6bfeebac | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
chris | 1:bd3f6bfeebac | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
chris | 1:bd3f6bfeebac | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
chris | 1:bd3f6bfeebac | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
chris | 1:bd3f6bfeebac | 21 | * THE SOFTWARE. |
chris | 1:bd3f6bfeebac | 22 | */ |
chris | 1:bd3f6bfeebac | 23 | |
chris | 1:bd3f6bfeebac | 24 | #ifndef PCA9532_H |
chris | 1:bd3f6bfeebac | 25 | #define PCA9532_H |
chris | 1:bd3f6bfeebac | 26 | |
chris | 1:bd3f6bfeebac | 27 | #include "mbed.h" |
chris | 1:bd3f6bfeebac | 28 | |
chris | 1:bd3f6bfeebac | 29 | /* |
chris | 1:bd3f6bfeebac | 30 | * register names |
chris | 1:bd3f6bfeebac | 31 | */ |
chris | 1:bd3f6bfeebac | 32 | |
chris | 1:bd3f6bfeebac | 33 | #define PCA9532_REG_INPUT0 0 |
chris | 1:bd3f6bfeebac | 34 | #define PCA9532_REG_INPUT1 1 |
chris | 1:bd3f6bfeebac | 35 | #define PCA9532_REG_PSC0 2 |
chris | 1:bd3f6bfeebac | 36 | #define PCA9532_REG_PWM0 3 |
chris | 1:bd3f6bfeebac | 37 | #define PCA9532_REG_PSC1 4 |
chris | 1:bd3f6bfeebac | 38 | #define PCA9532_REG_PWM1 5 |
chris | 1:bd3f6bfeebac | 39 | #define PCA9532_REG_LS0 6 |
chris | 1:bd3f6bfeebac | 40 | #define PCA9532_REG_LS1 7 |
chris | 1:bd3f6bfeebac | 41 | #define PCA9532_REG_LS2 8 |
chris | 1:bd3f6bfeebac | 42 | #define PCA9532_REG_LS3 9 |
chris | 1:bd3f6bfeebac | 43 | |
chris | 1:bd3f6bfeebac | 44 | /* |
chris | 1:bd3f6bfeebac | 45 | LED modes |
chris | 1:bd3f6bfeebac | 46 | */ |
chris | 1:bd3f6bfeebac | 47 | |
chris | 1:bd3f6bfeebac | 48 | #define MODE_OFF 0 |
chris | 1:bd3f6bfeebac | 49 | #define MODE_ON 1 |
chris | 1:bd3f6bfeebac | 50 | #define MODE_PWM0 2 |
chris | 1:bd3f6bfeebac | 51 | #define MODE_PWM1 3 |
chris | 1:bd3f6bfeebac | 52 | |
chris | 1:bd3f6bfeebac | 53 | class PCA9532 { |
chris | 1:bd3f6bfeebac | 54 | |
chris | 1:bd3f6bfeebac | 55 | public: |
chris | 1:bd3f6bfeebac | 56 | |
chris | 1:bd3f6bfeebac | 57 | /* |
chris | 1:bd3f6bfeebac | 58 | * Constructor |
chris | 1:bd3f6bfeebac | 59 | * Pass the I2C pins being used, and the address |
chris | 1:bd3f6bfeebac | 60 | * The address bottom bit will be replaced by R/W bit |
chris | 1:bd3f6bfeebac | 61 | */ |
chris | 1:bd3f6bfeebac | 62 | PCA9532(PinName sda, PinName scl, int addr); |
chris | 1:bd3f6bfeebac | 63 | |
chris | 1:bd3f6bfeebac | 64 | /* |
chris | 1:bd3f6bfeebac | 65 | * SetLed(int led, int mode) |
chris | 1:bd3f6bfeebac | 66 | * Set the LED (0-15) into the specified mode (0-3) (OFF, On, PWM0, PWM1) |
chris | 1:bd3f6bfeebac | 67 | */ |
chris | 1:bd3f6bfeebac | 68 | int SetLed (int led, int mode); |
chris | 1:bd3f6bfeebac | 69 | |
chris | 1:bd3f6bfeebac | 70 | /* |
chris | 1:bd3f6bfeebac | 71 | * SetMode(int mask, int mode) |
chris | 1:bd3f6bfeebac | 72 | * Set the LED specified in the mask to the given mode |
chris | 1:bd3f6bfeebac | 73 | */ |
chris | 1:bd3f6bfeebac | 74 | int SetMode (int mask, int mode); |
chris | 1:bd3f6bfeebac | 75 | |
chris | 1:bd3f6bfeebac | 76 | /* |
chris | 1:bd3f6bfeebac | 77 | * SetDuty(int channel, float duty) |
chris | 1:bd3f6bfeebac | 78 | * Set the duty cycle (0.0-1.0) of the specified PWM channel (0|1) |
chris | 1:bd3f6bfeebac | 79 | */ |
chris | 1:bd3f6bfeebac | 80 | int Duty (int channel, float duty); |
chris | 1:bd3f6bfeebac | 81 | |
chris | 1:bd3f6bfeebac | 82 | /* |
chris | 1:bd3f6bfeebac | 83 | * SetPeriod(int channel, float duty) |
chris | 1:bd3f6bfeebac | 84 | * Set the period (0.0-1.0) of the specified PWM channel (0|1) |
chris | 1:bd3f6bfeebac | 85 | */ |
chris | 1:bd3f6bfeebac | 86 | int Period (int channel, float period); |
chris | 1:bd3f6bfeebac | 87 | |
chris | 1:bd3f6bfeebac | 88 | protected: |
chris | 1:bd3f6bfeebac | 89 | |
chris | 1:bd3f6bfeebac | 90 | void _write(int reg, int data); |
chris | 1:bd3f6bfeebac | 91 | int _read(int reg); |
chris | 1:bd3f6bfeebac | 92 | int _addr; |
chris | 1:bd3f6bfeebac | 93 | I2C _i2c; |
chris | 1:bd3f6bfeebac | 94 | |
chris | 1:bd3f6bfeebac | 95 | }; |
chris | 1:bd3f6bfeebac | 96 | |
chris | 1:bd3f6bfeebac | 97 | |
chris | 1:bd3f6bfeebac | 98 | #endif |