Skip to content

Commit

Permalink
tree-wide: rename pbio_port_t to pbio_port_id_t
Browse files Browse the repository at this point in the history
This is consistent with using "id" for other similar lookup IDs and will
free up pbio_port_t to be used as a struct type.
  • Loading branch information
dlech committed Jun 29, 2021
1 parent 6cee08e commit c3f7947
Show file tree
Hide file tree
Showing 70 changed files with 200 additions and 200 deletions.
2 changes: 1 addition & 1 deletion lib/ev3dev/include/ev3dev_stretch/lego_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#include <pbio/error.h>
#include <pbio/iodev.h>

pbio_error_t ev3dev_lego_port_configure(pbio_port_t port, pbio_iodev_type_id_t id);
pbio_error_t ev3dev_lego_port_configure(pbio_port_id_t port, pbio_iodev_type_id_t id);

#endif // _PBIO_LEGO_PORT_H_
2 changes: 1 addition & 1 deletion lib/ev3dev/include/ev3dev_stretch/lego_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef enum {

typedef struct _lego_sensor_t lego_sensor_t;

pbio_error_t lego_sensor_get(lego_sensor_t **sensor, pbio_port_t port, pbio_iodev_type_id_t valid_id);
pbio_error_t lego_sensor_get(lego_sensor_t **sensor, pbio_port_id_t port, pbio_iodev_type_id_t valid_id);

pbio_error_t lego_sensor_get_info(lego_sensor_t *sensor, uint8_t *data_len, lego_sensor_data_type_t *data_type);

Expand Down
2 changes: 1 addition & 1 deletion lib/ev3dev/include/ev3dev_stretch/nxtcolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#include <pbio/error.h>
#include <pbio/iodev.h>

pbio_error_t nxtcolor_get_values_at_mode(pbio_port_t port, uint8_t mode, void *values);
pbio_error_t nxtcolor_get_values_at_mode(pbio_port_id_t port, uint8_t mode, void *values);

#endif // _PBIO_NXTCOLOR_H_
2 changes: 1 addition & 1 deletion lib/ev3dev/include/ev3dev_stretch/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <pbio/error.h>
#include <pbio/iodev.h>

pbio_error_t sysfs_get_number(pbio_port_t port, const char *rdir, int *sysfs_number);
pbio_error_t sysfs_get_number(pbio_port_id_t port, const char *rdir, int *sysfs_number);

pbio_error_t sysfs_open(FILE **file, const char *pathpat, int n, const char *attribute, const char *rw);

Expand Down
6 changes: 3 additions & 3 deletions lib/ev3dev/src/ev3dev_stretch/lego_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static const char* const port_modes[] = {
};

// Get the port mode
static pbio_error_t ev3dev_lego_port_get_mode(pbio_port_t port, const char *attribute, ev3dev_lego_port_t *port_mode) {
static pbio_error_t ev3dev_lego_port_get_mode(pbio_port_id_t port, const char *attribute, ev3dev_lego_port_t *port_mode) {
// Read lego-port number
int n_lport;
pbio_error_t err;
Expand Down Expand Up @@ -91,7 +91,7 @@ static pbio_error_t ev3dev_lego_port_get_mode(pbio_port_t port, const char *attr
}

// Write the port mode without questions
static pbio_error_t ev3dev_lego_port_set_mode(pbio_port_t port, ev3dev_lego_port_t mode) {
static pbio_error_t ev3dev_lego_port_set_mode(pbio_port_id_t port, ev3dev_lego_port_t mode) {

// Read lego-port number
int n_lport;
Expand Down Expand Up @@ -121,7 +121,7 @@ static pbio_error_t ev3dev_lego_port_set_mode(pbio_port_t port, ev3dev_lego_port
}

// Set compatible port configuration for given device
pbio_error_t ev3dev_lego_port_configure(pbio_port_t port, pbio_iodev_type_id_t id) {
pbio_error_t ev3dev_lego_port_configure(pbio_port_id_t port, pbio_iodev_type_id_t id) {
pbio_error_t err;

// Get the current port mode and status
Expand Down
8 changes: 4 additions & 4 deletions lib/ev3dev/src/ev3dev_stretch/lego_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct _lego_sensor_t {
uint8_t bin_data[PBIO_IODEV_MAX_DATA_SIZE] __attribute__((aligned(32)));
};
// Initialize an ev3dev sensor by opening the relevant sysfs attributes
static pbio_error_t ev3_sensor_init(lego_sensor_t *sensor, pbio_port_t port) {
static pbio_error_t ev3_sensor_init(lego_sensor_t *sensor, pbio_port_id_t port) {
pbio_error_t err;

err = sysfs_get_number(port, "/sys/class/lego-sensor", &sensor->n_sensor);
Expand Down Expand Up @@ -161,12 +161,12 @@ static pbio_error_t ev3_sensor_assert_id(lego_sensor_t *sensor, pbio_iodev_type_
struct _lego_sensor_t sensors[4];

// Get an ev3dev sensor
pbio_error_t lego_sensor_get(lego_sensor_t **sensor, pbio_port_t port, pbio_iodev_type_id_t valid_id) {
if (port < PBIO_PORT_1 || port > PBIO_PORT_4) {
pbio_error_t lego_sensor_get(lego_sensor_t **sensor, pbio_port_id_t port, pbio_iodev_type_id_t valid_id) {
if (port < PBIO_PORT_ID_1 || port > PBIO_PORT_ID_4) {
return PBIO_ERROR_INVALID_PORT;
}

*sensor = &sensors[port - PBIO_PORT_1];
*sensor = &sensors[port - PBIO_PORT_ID_1];

pbio_error_t err;

Expand Down
20 changes: 10 additions & 10 deletions lib/ev3dev/src/ev3dev_stretch/nxtcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ typedef struct {
} nxtcolor_pininfo_t;

static const nxtcolor_pininfo_t pininfo[4] = {
[PBIO_PORT_1 - PBIO_PORT_1] = {
[PBIO_PORT_ID_1 - PBIO_PORT_ID_1] = {
.digi0 = 2,
.digi1 = 15,
.adc_val = 5,
.adc_con = 6,
},
[PBIO_PORT_2 - PBIO_PORT_1] = {
[PBIO_PORT_ID_2 - PBIO_PORT_ID_1] = {
.digi0 = 14,
.digi1 = 13,
.adc_val = 7,
.adc_con = 8,
},
[PBIO_PORT_3 - PBIO_PORT_1] = {
[PBIO_PORT_ID_3 - PBIO_PORT_ID_1] = {
.digi0 = 12,
.digi1 = 30,
.adc_val = 9,
.adc_con = 10,
},
[PBIO_PORT_4 - PBIO_PORT_1] = {
[PBIO_PORT_ID_4 - PBIO_PORT_ID_1] = {
.digi0 = 1,
.digi1 = 31,
.adc_val = 11,
Expand Down Expand Up @@ -275,12 +275,12 @@ static pbio_error_t nxtcolor_send_byte(nxtcolor_t *nxtcolor, uint8_t msg)
return PBIO_SUCCESS;
}

static pbio_error_t nxtcolor_init_fs(nxtcolor_t *nxtcolor, pbio_port_t port) {
static pbio_error_t nxtcolor_init_fs(nxtcolor_t *nxtcolor, pbio_port_id_t port) {

pbio_error_t err;

// Get the pin info for this port
nxtcolor->pins = &pininfo[port-PBIO_PORT_1];
nxtcolor->pins = &pininfo[port-PBIO_PORT_ID_1];

// Open the sysfs files for this sensor
err = sysfs_open(&nxtcolor->f_digi0_val, "/sys/class/gpio/gpio%d/%s", nxtcolor->pins->digi0, "value", "w");
Expand Down Expand Up @@ -333,7 +333,7 @@ static pbio_error_t nxtcolor_init_fs(nxtcolor_t *nxtcolor, pbio_port_t port) {
return PBIO_SUCCESS;
}

static pbio_error_t nxtcolor_init(nxtcolor_t *nxtcolor, pbio_port_t port) {
static pbio_error_t nxtcolor_init(nxtcolor_t *nxtcolor, pbio_port_id_t port) {
pbio_error_t err;

// Init the file system
Expand Down Expand Up @@ -441,15 +441,15 @@ pbio_error_t nxtcolor_set_light(nxtcolor_t *nxtcolor, nxtcolor_color_state color
return PBIO_SUCCESS;
}

pbio_error_t nxtcolor_get_values_at_mode(pbio_port_t port, uint8_t mode, int32_t *values) {
pbio_error_t nxtcolor_get_values_at_mode(pbio_port_id_t port, uint8_t mode, int32_t *values) {

pbio_error_t err;

if (port < PBIO_PORT_1 || port > PBIO_PORT_4) {
if (port < PBIO_PORT_ID_1 || port > PBIO_PORT_ID_4) {
return PBIO_ERROR_INVALID_PORT;
}

nxtcolor_t *nxtcolor = &nxtcolorsensors[port-PBIO_PORT_1];
nxtcolor_t *nxtcolor = &nxtcolorsensors[port-PBIO_PORT_ID_1];

// We don't have a formal "get" function since the higher level code
// does not know about the color sensor being a special case. So instead
Expand Down
4 changes: 2 additions & 2 deletions lib/ev3dev/src/ev3dev_stretch/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define MAX_READ_LENGTH "60"

// Get the ev3dev sensor number for a given port
pbio_error_t sysfs_get_number(pbio_port_t port, const char *rdir, int *sysfs_number) {
pbio_error_t sysfs_get_number(pbio_port_id_t port, const char *rdir, int *sysfs_number) {
// Open lego-sensor directory in sysfs
DIR *d_sensor;
struct dirent *entry;
Expand Down Expand Up @@ -44,7 +44,7 @@ pbio_error_t sysfs_get_number(pbio_port_t port, const char *rdir, int *sysfs_num
if (fscanf(f_address, "ev3-ports:%*[a-z]%c", &port_char) < 1) {
return PBIO_ERROR_IO;
}
pbio_port_t port_found = port_char;
pbio_port_id_t port_found = port_char;

if (fclose(f_address) != 0) {
return PBIO_ERROR_IO;
Expand Down
32 changes: 16 additions & 16 deletions lib/pbio/drv/city_hub/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
#include <pbio/iodev.h>
#include <pbio/port.h>

pbio_error_t pbdrv_motor_coast(pbio_port_t port) {
pbio_error_t pbdrv_motor_coast(pbio_port_id_t port) {

// set both port pins 1 and 2 to output low
switch (port) {
case PBIO_PORT_B:
case PBIO_PORT_ID_B:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER6_Msk) | (1 << GPIO_MODER_MODER6_Pos);
GPIOC->BRR = GPIO_BRR_BR_6;
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER8_Msk) | (1 << GPIO_MODER_MODER8_Pos);
GPIOC->BRR = GPIO_BRR_BR_8;
break;
case PBIO_PORT_A:
case PBIO_PORT_ID_A:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER7_Msk) | (1 << GPIO_MODER_MODER7_Pos);
GPIOC->BRR = GPIO_BRR_BR_7;
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos);
Expand All @@ -40,16 +40,16 @@ pbio_error_t pbdrv_motor_coast(pbio_port_t port) {
return PBIO_SUCCESS;
}

static void pbdrv_motor_brake(pbio_port_t port) {
static void pbdrv_motor_brake(pbio_port_id_t port) {
// set both port pins 1 and 2 to output high
switch (port) {
case PBIO_PORT_B:
case PBIO_PORT_ID_B:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER6_Msk) | (1 << GPIO_MODER_MODER6_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_6;
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER8_Msk) | (1 << GPIO_MODER_MODER8_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_8;
break;
case PBIO_PORT_A:
case PBIO_PORT_ID_A:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER7_Msk) | (1 << GPIO_MODER_MODER7_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_7;
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos);
Expand All @@ -60,20 +60,20 @@ static void pbdrv_motor_brake(pbio_port_t port) {
}
}

static void pbdrv_motor_run_fwd(pbio_port_t port, int16_t duty_cycle) { // duty is pos
static void pbdrv_motor_run_fwd(pbio_port_id_t port, int16_t duty_cycle) { // duty is pos
pbdrv_pwm_dev_t *dev;

// one pin as out, high and the other as PWM
switch (port) {
case PBIO_PORT_B:
case PBIO_PORT_ID_B:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER6_Msk) | (1 << GPIO_MODER_MODER6_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_6;
if (pbdrv_pwm_get_dev(0, &dev) == PBIO_SUCCESS) {
pbdrv_pwm_set_duty(dev, 3, 1000 - duty_cycle / 10);
}
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER8_Msk) | (2 << GPIO_MODER_MODER8_Pos);
break;
case PBIO_PORT_A:
case PBIO_PORT_ID_A:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER7_Msk) | (1 << GPIO_MODER_MODER7_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_7;
if (pbdrv_pwm_get_dev(0, &dev) == PBIO_SUCCESS) {
Expand All @@ -86,20 +86,20 @@ static void pbdrv_motor_run_fwd(pbio_port_t port, int16_t duty_cycle) { // duty
}
}

static void pbdrv_motor_run_rev(pbio_port_t port, int16_t duty_cycle) { // duty is neg
static void pbdrv_motor_run_rev(pbio_port_id_t port, int16_t duty_cycle) { // duty is neg
pbdrv_pwm_dev_t *dev;

// one pin as out, high and the other as PWM
switch (port) {
case PBIO_PORT_B:
case PBIO_PORT_ID_B:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER8_Msk) | (1 << GPIO_MODER_MODER8_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_8;
if (pbdrv_pwm_get_dev(0, &dev) == PBIO_SUCCESS) {
pbdrv_pwm_set_duty(dev, 1, 1000 + duty_cycle / 10);
}
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER6_Msk) | (2 << GPIO_MODER_MODER6_Pos);
break;
case PBIO_PORT_A:
case PBIO_PORT_ID_A:
GPIOC->MODER = (GPIOC->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos);
GPIOC->BSRR = GPIO_BSRR_BS_9;
if (pbdrv_pwm_get_dev(0, &dev) == PBIO_SUCCESS) {
Expand All @@ -112,8 +112,8 @@ static void pbdrv_motor_run_rev(pbio_port_t port, int16_t duty_cycle) { // duty
}
}

pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_t port, int16_t duty_cycle) {
if (port < PBIO_PORT_A || port > PBIO_PORT_B) {
pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_id_t port, int16_t duty_cycle) {
if (port < PBIO_PORT_ID_A || port > PBIO_PORT_ID_B) {
return PBIO_ERROR_INVALID_PORT;
}

Expand All @@ -132,7 +132,7 @@ pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_t port, int16_t duty_cycle) {
return PBIO_SUCCESS;
}

pbio_error_t pbdrv_motor_get_id(pbio_port_t port, pbio_iodev_type_id_t *id) {
pbio_error_t pbdrv_motor_get_id(pbio_port_id_t port, pbio_iodev_type_id_t *id) {

pbio_iodev_t *iodev;
pbio_error_t err;
Expand All @@ -151,7 +151,7 @@ pbio_error_t pbdrv_motor_get_id(pbio_port_t port, pbio_iodev_type_id_t *id) {
return PBIO_SUCCESS;
}

pbio_error_t pbdrv_motor_setup(pbio_port_t port, bool is_servo) {
pbio_error_t pbdrv_motor_setup(pbio_port_id_t port, bool is_servo) {
return PBIO_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/drv/counter/counter_nxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

typedef struct {
pbdrv_counter_dev_t *dev;
pbio_port_t port;
pbio_port_id_t port;
} private_data_t;

static private_data_t private_data[PBDRV_CONFIG_COUNTER_NXT_NUM_DEV];
Expand Down
12 changes: 6 additions & 6 deletions lib/pbio/drv/ev3dev_stretch/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct _motor_t {

static motor_t motors[4];

static pbio_error_t ev3dev_motor_init(motor_t *mtr, pbio_port_t port) {
static pbio_error_t ev3dev_motor_init(motor_t *mtr, pbio_port_id_t port) {

pbio_error_t err;

Expand Down Expand Up @@ -107,7 +107,7 @@ static pbio_error_t ev3dev_motor_init(motor_t *mtr, pbio_port_t port) {
return sysfs_write_str(mtr->f_command, "stop");
}

static pbio_error_t ev3dev_motor_get(motor_t **motor, pbio_port_t port) {
static pbio_error_t ev3dev_motor_get(motor_t **motor, pbio_port_id_t port) {

// Verify port
if (port < PBDRV_CONFIG_FIRST_MOTOR_PORT || port > PBDRV_CONFIG_LAST_MOTOR_PORT) {
Expand All @@ -132,7 +132,7 @@ static pbio_error_t ev3dev_motor_connect_status(motor_t *mtr, pbio_error_t err)
return err;
}

pbio_error_t pbdrv_motor_coast(pbio_port_t port) {
pbio_error_t pbdrv_motor_coast(pbio_port_id_t port) {
// Get the motor and initialize if needed
pbio_error_t err;
motor_t *mtr;
Expand All @@ -150,7 +150,7 @@ pbio_error_t pbdrv_motor_coast(pbio_port_t port) {
return ev3dev_motor_connect_status(mtr, err);
}

pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_t port, int16_t duty_cycle) {
pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_id_t port, int16_t duty_cycle) {
// Get the motor and initialize if needed
pbio_error_t err;
motor_t *mtr;
Expand All @@ -171,7 +171,7 @@ pbio_error_t pbdrv_motor_set_duty_cycle(pbio_port_t port, int16_t duty_cycle) {
return ev3dev_motor_connect_status(mtr, err);
}

pbio_error_t pbdrv_motor_get_id(pbio_port_t port, pbio_iodev_type_id_t *id) {
pbio_error_t pbdrv_motor_get_id(pbio_port_id_t port, pbio_iodev_type_id_t *id) {
pbio_error_t err;
motor_t *mtr;
err = ev3dev_motor_get(&mtr, port);
Expand All @@ -182,7 +182,7 @@ pbio_error_t pbdrv_motor_get_id(pbio_port_t port, pbio_iodev_type_id_t *id) {
return ev3dev_motor_connect_status(mtr, PBIO_SUCCESS);
}

pbio_error_t pbdrv_motor_setup(pbio_port_t port, bool is_servo) {
pbio_error_t pbdrv_motor_setup(pbio_port_id_t port, bool is_servo) {

// Verify port
if (port < PBDRV_CONFIG_FIRST_MOTOR_PORT || port > PBDRV_CONFIG_LAST_MOTOR_PORT) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static void init_one(uint8_t ioport) {
}

// TODO: This should be moved to a common ioport_core.c file or removed entirely
pbio_error_t pbdrv_ioport_get_iodev(pbio_port_t port, pbio_iodev_t **iodev) {
pbio_error_t pbdrv_ioport_get_iodev(pbio_port_id_t port, pbio_iodev_t **iodev) {
if (port < PBDRV_CONFIG_IOPORT_LPF2_FIRST_PORT || port > PBDRV_CONFIG_IOPORT_LPF2_LAST_PORT) {
return PBIO_ERROR_INVALID_PORT;
}
Expand Down
Loading

0 comments on commit c3f7947

Please sign in to comment.