Wrapper library for controlling servos using Designer Systems DS-SCX18.Shield servo driver. See http://www.designersystems.co.uk/SCX18.S_info.htm
SCX18S.h@0:bf06c3ca958b, 2016-04-27 (annotated)
- Committer:
- Ingram
- Date:
- Wed Apr 27 14:16:45 2016 +0000
- Revision:
- 0:bf06c3ca958b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ingram | 0:bf06c3ca958b | 1 | #include "mbed.h" |
Ingram | 0:bf06c3ca958b | 2 | |
Ingram | 0:bf06c3ca958b | 3 | #define SCX18_I2C_BASE_ADDR 0x74 // DS-SCX18.S I2C base address |
Ingram | 0:bf06c3ca958b | 4 | #define SCX18_SERVO_ENABLED (1 << 7) |
Ingram | 0:bf06c3ca958b | 5 | #define SCX18_SERVO_REVERSED (1 << 6) |
Ingram | 0:bf06c3ca958b | 6 | #define SCX18_SERVO_SOFT_START (1 << 5) |
Ingram | 0:bf06c3ca958b | 7 | #define SCX18_SERVO_SPEED_CONTROL (1 << 4) |
Ingram | 0:bf06c3ca958b | 8 | #define SCX18_SERVO_MOVEMENT (1 << 4) |
Ingram | 0:bf06c3ca958b | 9 | |
Ingram | 0:bf06c3ca958b | 10 | union SCX18SServoStatusRegister { |
Ingram | 0:bf06c3ca958b | 11 | uint8_t value; |
Ingram | 0:bf06c3ca958b | 12 | struct { |
Ingram | 0:bf06c3ca958b | 13 | bool enabled; |
Ingram | 0:bf06c3ca958b | 14 | bool reversed; |
Ingram | 0:bf06c3ca958b | 15 | bool softstart; |
Ingram | 0:bf06c3ca958b | 16 | bool movement; |
Ingram | 0:bf06c3ca958b | 17 | uint8_t unpopulated : 4; |
Ingram | 0:bf06c3ca958b | 18 | } bits; |
Ingram | 0:bf06c3ca958b | 19 | }; |
Ingram | 0:bf06c3ca958b | 20 | |
Ingram | 0:bf06c3ca958b | 21 | class SCX18S |
Ingram | 0:bf06c3ca958b | 22 | { |
Ingram | 0:bf06c3ca958b | 23 | I2C i2c; |
Ingram | 0:bf06c3ca958b | 24 | uint8_t i2c_address; |
Ingram | 0:bf06c3ca958b | 25 | void writeRegister(uint8_t reg, uint8_t value); |
Ingram | 0:bf06c3ca958b | 26 | uint8_t readRegister(uint8_t reg); |
Ingram | 0:bf06c3ca958b | 27 | |
Ingram | 0:bf06c3ca958b | 28 | public: |
Ingram | 0:bf06c3ca958b | 29 | SCX18S(PinName p_sda, PinName p_scl, bool j_a0 = true, bool j_a1 = true); |
Ingram | 0:bf06c3ca958b | 30 | |
Ingram | 0:bf06c3ca958b | 31 | SCX18SServoStatusRegister readStatus(uint8_t channel); |
Ingram | 0:bf06c3ca958b | 32 | void writePosition(uint8_t channel, uint8_t position); |
Ingram | 0:bf06c3ca958b | 33 | void writeControl(uint8_t channel, bool enabled, bool reversed, bool softstart, bool speedcontrol, uint8_t speed); |
Ingram | 0:bf06c3ca958b | 34 | void writeEnable(); |
Ingram | 0:bf06c3ca958b | 35 | }; |