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