jim herd / SD21
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SD21.h Source File

SD21.h

00001 /*
00002     SD21 - 21 Channel Servo Driver Module Library
00003     Copyright (c) 2011 Jim Herd
00004     
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */    
00018 #ifndef     MBED_SD21_H
00019 #define     MBED_SD21_H
00020 
00021 #include    "mbed.h"
00022 
00023 #define     SD21_I2C_ADDRESS    0xC2
00024 #define     NOS_SD21_SERVOS       21
00025 
00026 #define     SERVO16_1     0
00027 #define     SERVO16_2     3
00028 
00029 #define     SERVO8_1     63
00030 #define     SERVO8_2     64
00031 
00032 typedef struct {
00033     int angle;
00034     int init_angle;
00035     int speed;
00036 } SD21_servo_state_t ;
00037 
00038 /** SD21 class
00039  *
00040  * Allow access to an SD21 21-channel servo controller unit
00041  *
00042  * @code
00043  *        SD21  servo_control
00044  * @endcode
00045  */
00046 class SD21 {
00047 public:
00048     /** Constructor for the SD21 connected to specified I2C pins at a specific address
00049      *
00050      * 21 Channel Servo Driver Module
00051      *
00052      * @param   sda         I2C data pin
00053      * @param   scl         I2C clock pin
00054      * @param   i2cAddress  I2C address
00055      */
00056     SD21(PinName sda, PinName scl);
00057 
00058     /** Reset SD21 device to its power-on state
00059      */    
00060     void reset(void);
00061 
00062     /** set a single servo value and associated speed using the full 16-bit registers
00063      *
00064      * @param   servo_num     1 to 21
00065      * @param   angle         0 to 90 (degrees)
00066      * @param   speed         0 to 255
00067      */   
00068     void set_servo(int servo_num, int angle, int speed);
00069 
00070 protected:
00071     I2C     _i2c;
00072     SD21_servo_state_t   servo_state[21];
00073     
00074     union {
00075         uint8_t  value8[4];
00076         uint16_t value16[2];
00077         uint32_t value32;
00078     } SD21_tmp_data;
00079 };
00080 
00081 #endif