/********************************************************************** Copyright (C) 2013 SARVESH KULKARNI Associate Professor, ECE Department Villanova University, PA, USA. LEGAL NOTICE: This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . This is the header file for the Library of routines for Adafruit's PCA9685 16-channel PWM breakout board. Version 0.8.01, Released April 2013. The Adafruit PWM board for which this library is written, is an I2C slave. You need to connect at least 4 pins from your microcontroller to drive the board. On the Raspberry Pi, Rev.2, these pins are as follows: SDA = pin 3, SCL = pin 5 VCC (3.3V) = pin 1, GND = pin 6 In addition, should you want to control any device with a power draw greater than that of an LED (e.g. servo motor) using this PWM board, you do need to provide a 5V power supply with sufficient amperage at the +V and GND p[ins of the PWM board. *********************************************************************/ #ifndef _ADAFRUIT_PCA9685 #define _ADAFRUIT_PCA9685 #include // for defns of unit8_t and unit16_t // ------ I2C Bus Addresses -------------------- #define GENERAL_CALL_ADDR 0x0 // -- PCA9685 Control Register Addresses -------- #define _MODE1_REG 0x0 #define _MODE2_REG 0x1 #define _SUBADR1 0x2 #define _SUBADR2 0x3 #define _SUBADR3 0x4 #define _LED0_ON_L 0x6 #define _LED0_ON_H 0x7 #define _LED0_OFF_L 0x8 #define _LED0_OFF_H 0x9 #define _ALL_LED_ON_L 0xFA #define _ALL_LED_ON_H 0xFB #define _ALL_LED_OFF_L 0xFC #define _ALL_LED_OFF_H 0xFD #define _PRE_SCALE_REG 0xFE // ------ Other Board/Chip Specific Constants and Control Codes ----------- #define SW_RESET 0x6 #define MODE1_REG_DEFAULT 0x01 // Restart=0, ExtClk=0, AutoIncr=1, Sleep=0, // Sub1-3=0, AllCall=1 #define MODE2_REG_DEFAULT 0xC // Output uninverted, LED o/ps: Totem Pole, // Outputs change on STOP #define OSC_CLK 25000000 // 25 MHz clock on board // ------ Error Codes for our Class -------------------- #define FD_UNINITIALIZED -1 // Illegal file descriptor; device file inaccessible #define DUTY_CYCLE_ILLEGAL -2 // Duty Cycle > 100 #define DELAY_ILLEGAL -3 // Delay > 100 #define CHANNEL_NUM_ILLEGAL -4 // Channel Num is not 255 (all), and not in 0-15 range class PWM_Board { public: PWM_Board(uint8_t i2c_addr = 0x40); bool isInitialized(); int setFreq(float freq); // freq in Hz // Duty cycle and delay are in percentages, channel_num 0xff means all channels int setDutyCycle(float duty_cycle, int channel_num = 0xff, float delay = 0); int sleep(void); int soft_reset(void); int hard_reset(void); protected: int initialize(void); private: uint8_t my_i2caddr; int my_fd; }; #endif