Hello World example for PCA9532 Library

Dependencies:   mbed

Committer:
chris
Date:
Fri May 07 10:30:15 2010 +0000
Revision:
0:836d73d25007

        

Who changed what in which revision?

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