summaryrefslogtreecommitdiffhomepage
path: root/digital/ai/src
diff options
context:
space:
mode:
Diffstat (limited to 'digital/ai/src')
-rw-r--r--digital/ai/src/twi_master/asserv.c42
-rw-r--r--digital/ai/src/twi_master/asserv.h3
-rw-r--r--digital/ai/src/twi_master/beacon.c2
-rw-r--r--digital/ai/src/twi_master/beacon.h3
-rw-r--r--digital/ai/src/twi_master/mimot.c24
-rw-r--r--digital/ai/src/twi_master/mimot.h3
-rw-r--r--digital/ai/src/twi_master/twi_master.c13
-rw-r--r--digital/ai/src/twi_master/twi_master.h23
8 files changed, 68 insertions, 45 deletions
diff --git a/digital/ai/src/twi_master/asserv.c b/digital/ai/src/twi_master/asserv.c
index 153997b6..ad36e00b 100644
--- a/digital/ai/src/twi_master/asserv.c
+++ b/digital/ai/src/twi_master/asserv.c
@@ -233,7 +233,7 @@ asserv_get_last_moving_direction (void)
void
asserv_reset (void)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'z';
twi_master_send_buffer (1);
}
@@ -241,7 +241,7 @@ asserv_reset (void)
void
asserv_free_motor (void)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'w';
twi_master_send_buffer (1);
}
@@ -249,7 +249,7 @@ asserv_free_motor (void)
void
asserv_stop_motor (void)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 's';
twi_master_send_buffer (1);
}
@@ -258,7 +258,7 @@ void
asserv_move_linearly (int32_t distance)
{
distance = fixed_mul_f824 (distance, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'l';
buffer[1] = v32_to_v8 (distance, 2);
buffer[2] = v32_to_v8 (distance, 1);
@@ -269,7 +269,7 @@ asserv_move_linearly (int32_t distance)
void
asserv_move_angularly (int16_t angle)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'a';
buffer[1] = v16_to_v8 (angle, 1);
buffer[2] = v16_to_v8 (angle, 0);
@@ -279,7 +279,7 @@ asserv_move_angularly (int16_t angle)
void
asserv_goto_angle (int16_t angle)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'y';
buffer[1] = v16_to_v8 (angle, 1);
buffer[2] = v16_to_v8 (angle, 0);
@@ -291,7 +291,7 @@ asserv_goto_xya (uint32_t x, uint32_t y, int16_t a, uint8_t backward)
{
x = fixed_mul_f824 (x, asserv_scale_inv);
y = fixed_mul_f824 (y, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'X';
buffer[1] = v32_to_v8 (x, 2);
buffer[2] = v32_to_v8 (x, 1);
@@ -308,7 +308,7 @@ asserv_goto_xya (uint32_t x, uint32_t y, int16_t a, uint8_t backward)
void
asserv_go_to_the_wall (uint8_t backward)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'f';
buffer[1] = backward;
twi_master_send_buffer (2);
@@ -322,7 +322,7 @@ asserv_push_the_wall (uint8_t backward, uint32_t init_x, uint32_t init_y,
init_x = fixed_mul_f824 (init_x, asserv_scale_inv);
if (init_y != (uint32_t) -1)
init_y = fixed_mul_f824 (init_y, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'G';
buffer[1] = backward;
buffer[2] = v32_to_v8 (init_x, 2);
@@ -341,7 +341,7 @@ asserv_push_the_wall (uint8_t backward, uint32_t init_x, uint32_t init_y,
void
asserv_move_motor0_absolute (uint16_t position, uint16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'b';
buffer[1] = v16_to_v8 (position, 1);
buffer[2] = v16_to_v8 (position, 0);
@@ -353,7 +353,7 @@ asserv_move_motor0_absolute (uint16_t position, uint16_t speed)
void
asserv_move_motor1_absolute (uint16_t position, uint16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'c';
buffer[1] = v16_to_v8 (position, 1);
buffer[2] = v16_to_v8 (position, 0);
@@ -368,7 +368,7 @@ void
asserv_set_x_position (int32_t x)
{
x = fixed_mul_f824 (x, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'p';
buffer[1] = 'X';
buffer[2] = v32_to_v8 (x, 2);
@@ -381,7 +381,7 @@ void
asserv_set_y_position (int32_t y)
{
y = fixed_mul_f824 (y, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'p';
buffer[1] = 'Y';
buffer[2] = v32_to_v8 (y, 2);
@@ -393,7 +393,7 @@ asserv_set_y_position (int32_t y)
void
asserv_set_angle_position (int16_t angle)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'p';
buffer[1] = 'A';
buffer[2] = v32_to_v8 (angle, 1);
@@ -405,7 +405,7 @@ void
asserv_set_speed (uint16_t linear_high, uint16_t angular_high,
uint16_t linear_low, uint16_t angular_low)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'p';
buffer[1] = 's';
buffer[2] = v16_to_v8 (linear_high, 1);
@@ -424,7 +424,7 @@ asserv_set_position (int32_t x, int32_t y, int16_t angle)
{
x = fixed_mul_f824 (x, asserv_scale_inv);
y = fixed_mul_f824 (y, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'p';
buffer[1] = 'X';
buffer[2] = v32_to_v8 (x, 2);
@@ -445,7 +445,7 @@ asserv_goto (uint32_t x, uint32_t y, uint8_t backward)
{
x = fixed_mul_f824 (x, asserv_scale_inv);
y = fixed_mul_f824 (y, asserv_scale_inv);
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'x';
buffer[1] = v32_to_v8 (x, 2);
buffer[2] = v32_to_v8 (x, 1);
@@ -462,7 +462,7 @@ asserv_goto (uint32_t x, uint32_t y, uint8_t backward)
void
asserv_motor0_zero_position (int16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'B';
buffer[1] = v16_to_v8 (speed, 1);
buffer[2] = v16_to_v8 (speed, 0);
@@ -472,7 +472,7 @@ asserv_motor0_zero_position (int16_t speed)
void
asserv_motor1_zero_position (int16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'C';
buffer[1] = v16_to_v8 (speed, 1);
buffer[2] = v16_to_v8 (speed, 0);
@@ -482,7 +482,7 @@ asserv_motor1_zero_position (int16_t speed)
void
asserv_motor0_free (void)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'r';
buffer[1] = 0;
twi_master_send_buffer (2);
@@ -491,7 +491,7 @@ asserv_motor0_free (void)
void
asserv_motor1_free (void)
{
- uint8_t *buffer = twi_master_get_buffer (ASSERV_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_ASSERV);
buffer[0] = 'r';
buffer[1] = 1;
twi_master_send_buffer (2);
diff --git a/digital/ai/src/twi_master/asserv.h b/digital/ai/src/twi_master/asserv.h
index ed6ed046..1cbcb187 100644
--- a/digital/ai/src/twi_master/asserv.h
+++ b/digital/ai/src/twi_master/asserv.h
@@ -32,9 +32,6 @@
* board using a protocol over TWI communication.
*/
-/** Slave number in twi_master list. */
-#define ASSERV_SLAVE 0
-
/** Asserv TWI address. */
#define ASSERV_TWI_ADDRESS 4
diff --git a/digital/ai/src/twi_master/beacon.c b/digital/ai/src/twi_master/beacon.c
index 6f3a3b2b..b9703d7b 100644
--- a/digital/ai/src/twi_master/beacon.c
+++ b/digital/ai/src/twi_master/beacon.c
@@ -65,7 +65,7 @@ beacon_status_cb (uint8_t *status)
void
beacon_on (uint8_t on_off)
{
- uint8_t *buffer = twi_master_get_buffer (BEACON_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_BEACON);
buffer[0] = on_off;
twi_master_send_buffer (1);
}
diff --git a/digital/ai/src/twi_master/beacon.h b/digital/ai/src/twi_master/beacon.h
index 2ff4e635..d0faa701 100644
--- a/digital/ai/src/twi_master/beacon.h
+++ b/digital/ai/src/twi_master/beacon.h
@@ -28,9 +28,6 @@
/** Interface with beacon board using the TWI protocol. */
-/** Slave number in the twi_master list. */
-#define BEACON_SLAVE 2
-
/** Beacon TWI address. */
#define BEACON_TWI_ADDRESS 10
diff --git a/digital/ai/src/twi_master/mimot.c b/digital/ai/src/twi_master/mimot.c
index 6346f7b9..6663f81f 100644
--- a/digital/ai/src/twi_master/mimot.c
+++ b/digital/ai/src/twi_master/mimot.c
@@ -118,7 +118,7 @@ mimot_get_motor1_position (void)
void
mimot_reset (void)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'z';
twi_master_send_buffer (1);
}
@@ -126,7 +126,7 @@ mimot_reset (void)
void
mimot_set_motor0_position (uint16_t position)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'p';
buffer[1] = 'Y';
buffer[2] = 0;
@@ -138,7 +138,7 @@ mimot_set_motor0_position (uint16_t position)
void
mimot_set_motor1_position (uint16_t position)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'p';
buffer[1] = 'Y';
buffer[2] = 1;
@@ -150,7 +150,7 @@ mimot_set_motor1_position (uint16_t position)
void
mimot_move_motor0_absolute (uint16_t position, uint16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'b';
buffer[1] = v16_to_v8 (position, 1);
buffer[2] = v16_to_v8 (position, 0);
@@ -162,7 +162,7 @@ mimot_move_motor0_absolute (uint16_t position, uint16_t speed)
void
mimot_move_motor1_absolute (uint16_t position, uint16_t speed)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'c';
buffer[1] = v16_to_v8 (position, 1);
buffer[2] = v16_to_v8 (position, 0);
@@ -187,7 +187,7 @@ void
mimot_motor0_find_zero (int16_t speed, uint8_t use_switch,
uint16_t reset_position)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'B';
buffer[1] = 0;
buffer[2] = v16_to_v8 (speed, 1);
@@ -202,7 +202,7 @@ void
mimot_motor1_find_zero (int16_t speed, uint8_t use_switch,
uint16_t reset_position)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'B';
buffer[1] = 1;
buffer[2] = v16_to_v8 (speed, 1);
@@ -216,7 +216,7 @@ mimot_motor1_find_zero (int16_t speed, uint8_t use_switch,
void
mimot_motor0_clamp (int16_t speed, int16_t pwm)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'l';
buffer[1] = 0;
buffer[2] = v16_to_v8 (speed, 1);
@@ -229,7 +229,7 @@ mimot_motor0_clamp (int16_t speed, int16_t pwm)
void
mimot_motor1_clamp (int16_t speed, int16_t pwm)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'l';
buffer[1] = 1;
buffer[2] = v16_to_v8 (speed, 1);
@@ -242,7 +242,7 @@ mimot_motor1_clamp (int16_t speed, int16_t pwm)
void
mimot_motor0_free (void)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'w';
buffer[1] = 0;
twi_master_send_buffer (2);
@@ -251,7 +251,7 @@ mimot_motor0_free (void)
void
mimot_motor1_free (void)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'w';
buffer[1] = 1;
twi_master_send_buffer (2);
@@ -260,7 +260,7 @@ mimot_motor1_free (void)
void
mimot_motor_output_set (uint8_t motor, int16_t pwm)
{
- uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE);
+ uint8_t *buffer = twi_master_get_buffer (TWI_MASTER_ID_MIMOT);
buffer[0] = 'W';
buffer[1] = motor;
buffer[2] = v16_to_v8 (pwm, 1);
diff --git a/digital/ai/src/twi_master/mimot.h b/digital/ai/src/twi_master/mimot.h
index 157ab4e1..78806154 100644
--- a/digital/ai/src/twi_master/mimot.h
+++ b/digital/ai/src/twi_master/mimot.h
@@ -30,9 +30,6 @@
* Provide interface to mimot board using the TWI protocol.
*/
-/** Slave number in the twi_master list. */
-#define MIMOT_SLAVE 1
-
/** Mimot TWI address. */
#define MIMOT_TWI_ADDRESS 6
diff --git a/digital/ai/src/twi_master/twi_master.c b/digital/ai/src/twi_master/twi_master.c
index ee401d7d..65acdce2 100644
--- a/digital/ai/src/twi_master/twi_master.c
+++ b/digital/ai/src/twi_master/twi_master.c
@@ -25,8 +25,12 @@
#include "common.h"
#include "twi_master.h"
-#include "asserv.h"
-#include "mimot.h"
+#if AC_AI_TWI_MASTER_ASSERV
+# include "asserv.h"
+#endif
+#if AC_AI_TWI_MASTER_MIMOT
+# include "mimot.h"
+#endif
#if AC_AI_TWI_MASTER_BEACON
# include "beacon.h"
#endif
@@ -101,8 +105,12 @@ struct twi_master_slave_t
/** Information on all slaves. */
static struct twi_master_slave_t twi_master_slaves[] = {
+#if AC_AI_TWI_MASTER_ASSERV
{ ASSERV_TWI_ADDRESS, 0, ASSERV_STATUS_LENGTH, asserv_status_cb },
+#endif
+#if AC_AI_TWI_MASTER_MIMOT
{ MIMOT_TWI_ADDRESS, 0, MIMOT_STATUS_LENGTH, mimot_status_cb },
+#endif
#if AC_AI_TWI_MASTER_BEACON
{ BEACON_TWI_ADDRESS, 0, BEACON_STATUS_LENGTH, beacon_status_cb },
#endif
@@ -197,6 +205,7 @@ twi_master_sync (void)
uint8_t *
twi_master_get_buffer (uint8_t slave)
{
+ assert (slave < TWI_MASTER_DISABLED);
assert (twi_master.pending_nb < TWI_MASTER_PENDING_MAX);
struct twi_master_command_t *c =
&twi_master.pending[TWI_MASTER_PENDING_TAIL];
diff --git a/digital/ai/src/twi_master/twi_master.h b/digital/ai/src/twi_master/twi_master.h
index e75dbfab..4908f471 100644
--- a/digital/ai/src/twi_master/twi_master.h
+++ b/digital/ai/src/twi_master/twi_master.h
@@ -49,6 +49,29 @@
* transmission until the first command is acknowledged.
*/
+/** Slave identifiers. */
+enum {
+#if AC_AI_TWI_MASTER_ASSERV
+ TWI_MASTER_ID_ASSERV,
+#endif
+#if AC_AI_TWI_MASTER_MIMOT
+ TWI_MASTER_ID_MIMOT,
+#endif
+#if AC_AI_TWI_MASTER_BEACON
+ TWI_MASTER_ID_BEACON,
+#endif
+ TWI_MASTER_DISABLED = 127,
+#if !AC_AI_TWI_MASTER_ASSERV
+ TWI_MASTER_ID_ASSERV,
+#endif
+#if !AC_AI_TWI_MASTER_MIMOT
+ TWI_MASTER_ID_MIMOT,
+#endif
+#if !AC_AI_TWI_MASTER_BEACON
+ TWI_MASTER_ID_BEACON,
+#endif
+};
+
/** Initialise module. */
void
twi_master_init (void);