Access SD21 21 channel servo controller

Committer:
jimherd
Date:
Thu Feb 09 23:41:43 2012 +0000
Revision:
3:f8b3023564af
Parent:
2:292c59c8c51e
Minor fix. Index issue.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jimherd 0:0f81e14bfae9 1 /*
jimherd 0:0f81e14bfae9 2 SD21 - 21 Channel Servo Driver Module Library
jimherd 0:0f81e14bfae9 3 Copyright (c) 2011 Jim Herd
jimherd 0:0f81e14bfae9 4
jimherd 0:0f81e14bfae9 5 This program is free software: you can redistribute it and/or modify
jimherd 0:0f81e14bfae9 6 it under the terms of the GNU General Public License as published by
jimherd 0:0f81e14bfae9 7 the Free Software Foundation, either version 3 of the License, or
jimherd 0:0f81e14bfae9 8 (at your option) any later version.
jimherd 0:0f81e14bfae9 9
jimherd 0:0f81e14bfae9 10 This program is distributed in the hope that it will be useful,
jimherd 0:0f81e14bfae9 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
jimherd 0:0f81e14bfae9 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
jimherd 0:0f81e14bfae9 13 GNU General Public License for more details.
jimherd 0:0f81e14bfae9 14
jimherd 0:0f81e14bfae9 15 You should have received a copy of the GNU General Public License
jimherd 0:0f81e14bfae9 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
jimherd 0:0f81e14bfae9 17 */
jimherd 0:0f81e14bfae9 18 #ifndef MBED_SD21_H
jimherd 0:0f81e14bfae9 19 #define MBED_SD21_H
jimherd 0:0f81e14bfae9 20
jimherd 0:0f81e14bfae9 21 #include "mbed.h"
jimherd 0:0f81e14bfae9 22
jimherd 0:0f81e14bfae9 23 #define SD21_I2C_ADDRESS 0xC2
jimherd 1:b9fd24c9f6ef 24 #define NOS_SD21_SERVOS 21
jimherd 0:0f81e14bfae9 25
jimherd 0:0f81e14bfae9 26 #define SERVO16_1 0
jimherd 0:0f81e14bfae9 27 #define SERVO16_2 3
jimherd 0:0f81e14bfae9 28
jimherd 0:0f81e14bfae9 29 #define SERVO8_1 63
jimherd 0:0f81e14bfae9 30 #define SERVO8_2 64
jimherd 0:0f81e14bfae9 31
jimherd 0:0f81e14bfae9 32 typedef struct {
jimherd 0:0f81e14bfae9 33 int angle;
jimherd 0:0f81e14bfae9 34 int init_angle;
jimherd 0:0f81e14bfae9 35 int speed;
jimherd 0:0f81e14bfae9 36 } SD21_servo_state_t ;
jimherd 0:0f81e14bfae9 37
jimherd 2:292c59c8c51e 38 /** SD21 class
jimherd 2:292c59c8c51e 39 *
jimherd 2:292c59c8c51e 40 * Allow access to an SD21 21-channel servo controller unit
jimherd 2:292c59c8c51e 41 *
jimherd 2:292c59c8c51e 42 * @code
jimherd 2:292c59c8c51e 43 * SD21 servo_control
jimherd 2:292c59c8c51e 44 * @endcode
jimherd 2:292c59c8c51e 45 */
jimherd 0:0f81e14bfae9 46 class SD21 {
jimherd 0:0f81e14bfae9 47 public:
jimherd 0:0f81e14bfae9 48 /** Constructor for the SD21 connected to specified I2C pins at a specific address
jimherd 0:0f81e14bfae9 49 *
jimherd 0:0f81e14bfae9 50 * 21 Channel Servo Driver Module
jimherd 0:0f81e14bfae9 51 *
jimherd 0:0f81e14bfae9 52 * @param sda I2C data pin
jimherd 0:0f81e14bfae9 53 * @param scl I2C clock pin
jimherd 0:0f81e14bfae9 54 * @param i2cAddress I2C address
jimherd 0:0f81e14bfae9 55 */
jimherd 0:0f81e14bfae9 56 SD21(PinName sda, PinName scl);
jimherd 0:0f81e14bfae9 57
jimherd 0:0f81e14bfae9 58 /** Reset SD21 device to its power-on state
jimherd 0:0f81e14bfae9 59 */
jimherd 0:0f81e14bfae9 60 void reset(void);
jimherd 0:0f81e14bfae9 61
jimherd 0:0f81e14bfae9 62 /** set a single servo value and associated speed using the full 16-bit registers
jimherd 0:0f81e14bfae9 63 *
jimherd 0:0f81e14bfae9 64 * @param servo_num 1 to 21
jimherd 0:0f81e14bfae9 65 * @param angle 0 to 90 (degrees)
jimherd 0:0f81e14bfae9 66 * @param speed 0 to 255
jimherd 0:0f81e14bfae9 67 */
jimherd 0:0f81e14bfae9 68 void set_servo(int servo_num, int angle, int speed);
jimherd 0:0f81e14bfae9 69
jimherd 0:0f81e14bfae9 70 protected:
jimherd 0:0f81e14bfae9 71 I2C _i2c;
jimherd 0:0f81e14bfae9 72 SD21_servo_state_t servo_state[21];
jimherd 0:0f81e14bfae9 73
jimherd 0:0f81e14bfae9 74 union {
jimherd 0:0f81e14bfae9 75 uint8_t value8[4];
jimherd 0:0f81e14bfae9 76 uint16_t value16[2];
jimherd 0:0f81e14bfae9 77 uint32_t value32;
jimherd 0:0f81e14bfae9 78 } SD21_tmp_data;
jimherd 0:0f81e14bfae9 79 };
jimherd 0:0f81e14bfae9 80
jimherd 0:0f81e14bfae9 81 #endif