Go to the documentation of this file.
38 #include "mikrosdk_version.h"
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
62 #define SERVO_MAP_MIKROBUS( cfg, mikrobus ) \
63 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65 cfg.oe = MIKROBUS( mikrobus, MIKROBUS_CS )
72 #define SERVO_RETVAL uint8_t
75 #define SERVO_INIT_ERROR 0xFF
82 #define SERVO_REG_MODE_1 0x00
83 #define SERVO_REG_MODE_2 0x01
84 #define SERVO_REG_SUB_ADDRESS_1 0x02
85 #define SERVO_REG_SUB_ADDRESS_2 0x03
86 #define SERVO_REG_SUB_ADDRESS_3 0x04
87 #define SERVO_REG_ALL_CALL_ADR 0x05
89 #define SERVO_REG_MOTOR_1_ON_L 0x06
90 #define SERVO_REG_MOTOR_1_ON_H 0x07
91 #define SERVO_REG_MOTOR_1_OFF_L 0x08
92 #define SERVO_REG_MOTOR_1_OFF_H 0x09
93 #define SERVO_REG_MOTOR_2_ON_L 0x0A
94 #define SERVO_REG_MOTOR_2_ON_H 0x0B
95 #define SERVO_REG_MOTOR_2_OFF_L 0x0C
96 #define SERVO_REG_MOTOR_2_OFF_H 0x0D
97 #define SERVO_REG_MOTOR_3_ON_L 0x0E
98 #define SERVO_REG_MOTOR_3_ON_H 0x0F
99 #define SERVO_REG_MOTOR_3_OFF_L 0x10
100 #define SERVO_REG_MOTOR_3_OFF_H 0x11
101 #define SERVO_REG_MOTOR_4_ON_L 0x12
102 #define SERVO_REG_MOTOR_4_ON_H 0x13
103 #define SERVO_REG_MOTOR_4_OFF_L 0x14
104 #define SERVO_REG_MOTOR_4_OFF_H 0x15
105 #define SERVO_REG_MOTOR_5_ON_L 0x16
106 #define SERVO_REG_MOTOR_5_ON_H 0x17
107 #define SERVO_REG_MOTOR_5_OFF_L 0x18
108 #define SERVO_REG_MOTOR_5_OFF_H 0x19
109 #define SERVO_REG_MOTOR_6_ON_L 0x1A
110 #define SERVO_REG_MOTOR_6_ON_H 0x1B
111 #define SERVO_REG_MOTOR_6_OFF_L 0x1C
112 #define SERVO_REG_MOTOR_6_OFF_H 0x1D
113 #define SERVO_REG_MOTOR_7_ON_L 0x1E
114 #define SERVO_REG_MOTOR_7_ON_H 0x1F
115 #define SERVO_REG_MOTOR_7_OFF_L 0x20
116 #define SERVO_REG_MOTOR_7_OFF_H 0x21
117 #define SERVO_REG_MOTOR_8_ON_L 0x22
118 #define SERVO_REG_MOTOR_8_ON_H 0x23
119 #define SERVO_REG_MOTOR_8_OFF_L 0x24
120 #define SERVO_REG_MOTOR_8_OFF_H 0x25
121 #define SERVO_REG_MOTOR_9_ON_L 0x26
122 #define SERVO_REG_MOTOR_9_ON_H 0x27
123 #define SERVO_REG_MOTOR_9_OFF_L 0x28
124 #define SERVO_REG_MOTOR_9_OFF_H 0x29
125 #define SERVO_REG_MOTOR_10_ON_L 0x2A
126 #define SERVO_REG_MOTOR_10_ON_H 0x2B
127 #define SERVO_REG_MOTOR_10_OFF_L 0x2C
128 #define SERVO_REG_MOTOR_10_OFF_H 0x2D
129 #define SERVO_REG_MOTOR_11_ON_L 0x2E
130 #define SERVO_REG_MOTOR_11_ON_H 0x2F
131 #define SERVO_REG_MOTOR_11_OFF_L 0x30
132 #define SERVO_REG_MOTOR_11_OFF_H 0x31
133 #define SERVO_REG_MOTOR_12_ON_L 0x32
134 #define SERVO_REG_MOTOR_12_ON_H 0x33
135 #define SERVO_REG_MOTOR_12_OFF_L 0x34
136 #define SERVO_REG_MOTOR_12_OFF_H 0x35
137 #define SERVO_REG_MOTOR_13_ON_L 0x36
138 #define SERVO_REG_MOTOR_13_ON_H 0x37
139 #define SERVO_REG_MOTOR_13_OFF_L 0x38
140 #define SERVO_REG_MOTOR_13_OFF_H 0x39
141 #define SERVO_REG_MOTOR_14_ON_L 0x3A
142 #define SERVO_REG_MOTOR_14_ON_H 0x3B
143 #define SERVO_REG_MOTOR_14_OFF_L 0x3C
144 #define SERVO_REG_MOTOR_14_OFF_H 0x3D
145 #define SERVO_REG_MOTOR_15_ON_L 0x3E
146 #define SERVO_REG_MOTOR_15_ON_H 0x3F
147 #define SERVO_REG_MOTOR_15_OFF_L 0x40
148 #define SERVO_REG_MOTOR_15_OFF_H 0x41
149 #define SERVO_REG_MOTOR_16_ON_L 0x42
150 #define SERVO_REG_MOTOR_16_ON_H 0x43
151 #define SERVO_REG_MOTOR_16_OFF_L 0x44
152 #define SERVO_REG_MOTOR_16_OFF_H 0x45
154 #define SERVO_REG_ALL_MOTOR_ON_L 0xFA
155 #define SERVO_REG_ALL_MOTOR_ON_H 0xFB
156 #define SERVO_REG_ALL_MOTOR_OFF_L 0xFC
157 #define SERVO_REG_ALL_MOTOR_OFF_H 0xFD
158 #define SERVO_REG_PRE_SCALE 0xFE
159 #define SERVO_REG_TEST_MODE 0xFF
166 #define SERVO_MODE1_RESTART_ENABLE 0x01 << 7
167 #define SERVO_MODE1_RESTART_DISABLE 0x00 << 7
168 #define SERVO_MODE1_INTERNAL_CLOCK 0x00 << 6
169 #define SERVO_MODE1_EXTCLK_PIN_CLOCK 0x01 << 6
170 #define SERVO_MODE1_AUTO_INCREMENT_ENABLE 0x01 << 5
171 #define SERVO_MODE1_AUTO_INCREMENT_DISABLE 0x00 << 5
172 #define SERVO_MODE1_NORMAL_MODE 0x00 << 4
173 #define SERVO_MODE1_LOW_POWER_MODE 0x01 << 4
174 #define SERVO_MODE1_USE_SUBADR_1 0x01 << 3
175 #define SERVO_MODE1_NO_USE_SUBADR_1 0x00 << 3
176 #define SERVO_MODE1_USE_SUBADR_2 0x01 << 2
177 #define SERVO_MODE1_NO_USE_SUBADR_2 0x00 << 2
178 #define SERVO_MODE1_USE_SUBADR_3 0x01 << 1
179 #define SERVO_MODE1_NO_USE_SUBADR_3 0x00 << 1
180 #define SERVO_MODE1_USE_ALL_CALL_ADR 0x01
181 #define SERVO_MODE1_NO_USE_ALL_CALL_ADR 0x00
188 #define SERVO_MODE2_OUT_LOGIC_NOT_INVERTED 0x00 << 4
189 #define SERVO_MODE2_OUT_LOGIC_INVERTED 0x01 << 4
190 #define SERVO_MODE2_OUT_CHANGE_ON_STOP_CMD 0x00 << 3
191 #define SERVO_MODE2_OUT_CHANGE_ON_ACK_CMD 0x01 << 3
192 #define SERVO_MODE2_OPEN_DRAIN_STRUCTURE 0x00 << 2
193 #define SERVO_MODE2_TOTEM_POLE_STRUCTURE 0x01 << 2
200 #define SERVO_DEFAULT_LOW_RESOLUTION 0
201 #define SERVO_DEFAULT_HIGH_RESOLUTION 330
203 #define SERVO_GENERAL_CALL_ADR 0x00
204 #define SERVO_SOFT_RESET 0x06
206 #define SERVO_VREF_3300 3300
207 #define SERVO_VREF_5000 5000
214 #define SERVO_MOTOR_1 0x06
215 #define SERVO_MOTOR_2 0x0A
216 #define SERVO_MOTOR_3 0x0E
217 #define SERVO_MOTOR_4 0x12
218 #define SERVO_MOTOR_5 0x16
219 #define SERVO_MOTOR_6 0x1A
220 #define SERVO_MOTOR_7 0x1E
221 #define SERVO_MOTOR_8 0x22
222 #define SERVO_MOTOR_9 0x26
223 #define SERVO_MOTOR_10 0x2A
224 #define SERVO_MOTOR_11 0x2E
225 #define SERVO_MOTOR_12 0x32
226 #define SERVO_MOTOR_13 0x36
227 #define SERVO_MOTOR_14 0x3A
228 #define SERVO_MOTOR_15 0x3E
229 #define SERVO_MOTOR_16 0x42
231 #define SERVO_POSITIVE_CH0_NEGATIVE_CH1 0xA0
232 #define SERVO_POSITIVE_CH2_NEGATIVE_CH3 0xA1
233 #define SERVO_POSITIVE_CH4_NEGATIVE_CH5 0xA2
234 #define SERVO_POSITIVE_CH6_NEGATIVE_CH7 0xA3
235 #define SERVO_POSITIVE_CH8_NEGATIVE_CH9 0xA4
236 #define SERVO_POSITIVE_CH10_NEGATIVE_CH11 0xA5
237 #define SERVO_POSITIVE_CH12_NEGATIVE_CH13 0xA6
238 #define SERVO_POSITIVE_CH14_NEGATIVE_CH15 0xA7
239 #define SERVO_POSITIVE_CH1_NEGATIVE_CH0 0xA8
240 #define SERVO_POSITIVE_CH3_NEGATIVE_CH2 0xA9
241 #define SERVO_POSITIVE_CH5_NEGATIVE_CH4 0xAA
242 #define SERVO_POSITIVE_CH7_NEGATIVE_CH6 0xAB
243 #define SERVO_POSITIVE_CH9_NEGATIVE_CH8 0xAC
244 #define SERVO_POSITIVE_CH11_NEGATIVE_CH10 0xAD
245 #define SERVO_POSITIVE_CH13_NEGATIVE_CH12 0xAE
246 #define SERVO_POSITIVE_CH15_NEGATIVE_CH14 0xAF
248 #define SERVO_POSITIVE_CH0 0xB0
249 #define SERVO_POSITIVE_CH2 0xB1
250 #define SERVO_POSITIVE_CH4 0xB2
251 #define SERVO_POSITIVE_CH6 0xB3
252 #define SERVO_POSITIVE_CH8 0xB4
253 #define SERVO_POSITIVE_CH10 0xB5
254 #define SERVO_POSITIVE_CH12 0xB6
255 #define SERVO_POSITIVE_CH14 0xB7
256 #define SERVO_POSITIVE_CH1 0xB8
257 #define SERVO_POSITIVE_CH3 0xB9
258 #define SERVO_POSITIVE_CH5 0xBA
259 #define SERVO_POSITIVE_CH7 0xBB
260 #define SERVO_POSITIVE_CH9 0xBC
261 #define SERVO_POSITIVE_CH11 0xBD
262 #define SERVO_POSITIVE_CH13 0xBE
263 #define SERVO_POSITIVE_CH15 0xBF
uint8_t min_position
Definition: servo.h:275
void servo_generic_write_of_pca9685(servo_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function of pca9685.
uint16_t setvo_get_current(servo_t *ctx, uint8_t channel)
Functions for reading current in mA.
#define SERVO_RETVAL
Definition: servo.h:72
void servo_generic_write_of_of_ltc2497(servo_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function of ltc2497.
uint8_t in_max
Definition: servo.h:286
uint8_t max_pos
Definition: servo.h:311
servo_pos_and_res_t pos_and_res
Definition: servo.h:316
Click ctx object definition.
Definition: servo.h:296
i2c_master_t i2c
Definition: servo.h:303
void servo_generic_read_of_pca9685(servo_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function of pca9685.
void servo_cfg_setup(servo_cfg_t *cfg)
Config Object Initialization function.
void servo_setting(servo_t *ctx, servo_pos_and_res_t pos_and_res)
Setting function.
void servo_generic_read_of_ltc2497(servo_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function of ltc2497.
void servo_soft_reset(servo_t *ctx)
Soft reset function.
SERVO_RETVAL servo_init(servo_t *ctx, servo_cfg_t *cfg)
Initialization function.
digital_out_t oe
Definition: servo.h:299
void servo_stop(servo_t *ctx)
Stop function.
uint8_t slave_address_of_pca9685
Definition: servo.h:307
uint8_t max_position
Definition: servo.h:276
uint16_t out_max
Definition: servo.h:288
void servo_default_cfg(servo_t *ctx)
Click Default Configuration function.
void servo_set_mode(servo_t *ctx, uint8_t mode, uint8_t w_data)
Set mode function.
void servo_start(servo_t *ctx)
Start function.
pin_name_t oe
Definition: servo.h:332
uint16_t low_resolution
Definition: servo.h:277
void servo_set_freq(servo_t *ctx, uint16_t freq)
Set frequency function.
void servo_set_vref(servo_t *ctx, uint16_t v_ref)
Set Vref function.
uint32_t i2c_speed
Definition: servo.h:336
uint16_t low_res
Definition: servo.h:313
void servo_sleep(servo_t *ctx)
Sleep function.
uint16_t vref
Definition: servo.h:312
uint16_t high_resolution
Definition: servo.h:278
uint16_t high_res
Definition: servo.h:314
uint8_t x
Definition: servo.h:284
uint8_t min_pos
Definition: servo.h:310
pin_name_t scl
Definition: servo.h:327
uint8_t slave_address_of_ltc2497
Definition: servo.h:308
uint8_t i2c_address_of_pca9685
Definition: servo.h:337
uint16_t out_min
Definition: servo.h:287
Click configuration structure definition.
Definition: servo.h:324
uint32_t servo_get_channel(servo_t *ctx, uint8_t channel)
Functions for reading adc value of current.
pin_name_t sda
Definition: servo.h:328
void servo_set_position(servo_t *ctx, uint8_t motor, uint8_t position)
Set position function.
uint8_t in_min
Definition: servo.h:285
uint8_t i2c_address_of_ltc2497
Definition: servo.h:338