Example of PCA9532 being used on the Embedded Artists Baseboard, this time fading up LEDs using PWM

Dependencies:   mbed

Committer:
chris
Date:
Fri May 07 12:41:06 2010 +0000
Revision:
0:0df46cf615c3

        

Who changed what in which revision?

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