Skip to content
Snippets Groups Projects
Commit 412fc625 authored by swym's avatar swym
Browse files

gpio: rename constants to differentiate them from MAXIM's GPIO_ library

parent 26db6b6b
No related branches found
No related tags found
No related merge requests found
...@@ -427,26 +427,26 @@ API(API_BUTTONS_READ, uint8_t epic_buttons_read(uint8_t mask)); ...@@ -427,26 +427,26 @@ API(API_BUTTONS_READ, uint8_t epic_buttons_read(uint8_t mask));
/** GPIO pins IDs */ /** GPIO pins IDs */
enum gpio_pin { enum gpio_pin {
/** ``1``, Wristband connector 1 */ /** ``1``, Wristband connector 1 */
GPIO_WRISTBAND_1 = 1, EPIC_GPIO_WRISTBAND_1 = 1,
/** ``2``, Wristband connector 2 */ /** ``2``, Wristband connector 2 */
GPIO_WRISTBAND_2 = 2, EPIC_GPIO_WRISTBAND_2 = 2,
/** ``3``, Wristband connector 3 */ /** ``3``, Wristband connector 3 */
GPIO_WRISTBAND_3 = 3, EPIC_GPIO_WRISTBAND_3 = 3,
/** ``4``, Wristband connector 4 */ /** ``4``, Wristband connector 4 */
GPIO_WRISTBAND_4 = 4, EPIC_GPIO_WRISTBAND_4 = 4,
}; };
/** GPIO pin modes */ /** GPIO pin modes */
enum gpio_mode { enum gpio_mode {
/** Configure the pin as input */ /** Configure the pin as input */
GPIO_MODE_IN = (1<<0), EPIC_GPIO_MODE_IN = (1<<0),
/** Configure the pin as output */ /** Configure the pin as output */
GPIO_MODE_OUT = (1<<1), EPIC_GPIO_MODE_OUT = (1<<1),
/** Enable the internal pull-up resistor */ /** Enable the internal pull-up resistor */
GPIO_PULL_UP = (1<<6), EPIC_GPIO_PULL_UP = (1<<6),
/** Enable the internal pull-down resistor */ /** Enable the internal pull-down resistor */
GPIO_PULL_DOWN = (1<<7), EPIC_GPIO_PULL_DOWN = (1<<7),
}; };
/** /**
......
...@@ -8,36 +8,48 @@ ...@@ -8,36 +8,48 @@
* pins for wristband GPIO 1-4 (not 0-3 as the schematic states) * pins for wristband GPIO 1-4 (not 0-3 as the schematic states)
*/ */
static gpio_cfg_t gpio_configs[] = { static gpio_cfg_t gpio_configs[] = {
[GPIO_WRISTBAND_1] = { PORT_0, PIN_21, GPIO_FUNC_OUT, GPIO_PAD_NONE }, [EPIC_GPIO_WRISTBAND_1] = { PORT_0,
[GPIO_WRISTBAND_2] = { PORT_0, PIN_22, GPIO_FUNC_OUT, GPIO_PAD_NONE }, PIN_21,
[GPIO_WRISTBAND_3] = { PORT_0, PIN_29, GPIO_FUNC_OUT, GPIO_PAD_NONE }, GPIO_FUNC_OUT,
[GPIO_WRISTBAND_4] = { PORT_0, PIN_20, GPIO_FUNC_OUT, GPIO_PAD_NONE }, GPIO_PAD_NONE },
[EPIC_GPIO_WRISTBAND_2] = { PORT_0,
PIN_22,
GPIO_FUNC_OUT,
GPIO_PAD_NONE },
[EPIC_GPIO_WRISTBAND_3] = { PORT_0,
PIN_29,
GPIO_FUNC_OUT,
GPIO_PAD_NONE },
[EPIC_GPIO_WRISTBAND_4] = { PORT_0,
PIN_20,
GPIO_FUNC_OUT,
GPIO_PAD_NONE },
}; };
int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode) int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
{ {
if (pin < GPIO_WRISTBAND_1 || pin > GPIO_WRISTBAND_4) if (pin < EPIC_GPIO_WRISTBAND_1 || pin > EPIC_GPIO_WRISTBAND_4)
return -EINVAL; return -EINVAL;
gpio_cfg_t *cfg = &gpio_configs[pin]; gpio_cfg_t *cfg = &gpio_configs[pin];
if (mode & GPIO_MODE_IN) { if (mode & EPIC_GPIO_MODE_IN) {
cfg->func = GPIO_FUNC_IN; cfg->func = GPIO_FUNC_IN;
if (mode & GPIO_MODE_OUT) { if (mode & EPIC_GPIO_MODE_OUT) {
return -EINVAL; return -EINVAL;
} }
} else if (mode & GPIO_MODE_OUT) { } else if (mode & EPIC_GPIO_MODE_OUT) {
cfg->func = GPIO_FUNC_OUT; cfg->func = GPIO_FUNC_OUT;
if (mode & GPIO_MODE_IN) { if (mode & EPIC_GPIO_MODE_IN) {
return -EINVAL; return -EINVAL;
} }
} else { } else {
return -EINVAL; return -EINVAL;
} }
if (mode & GPIO_PULL_UP) { if (mode & EPIC_GPIO_PULL_UP) {
cfg->pad = GPIO_PAD_PULL_UP; cfg->pad = GPIO_PAD_PULL_UP;
} else if (mode & GPIO_PULL_DOWN) { } else if (mode & EPIC_GPIO_PULL_DOWN) {
cfg->pad = GPIO_PAD_PULL_DOWN; cfg->pad = GPIO_PAD_PULL_DOWN;
} else { } else {
cfg->pad = GPIO_PAD_NONE; cfg->pad = GPIO_PAD_NONE;
...@@ -50,26 +62,26 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode) ...@@ -50,26 +62,26 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
int epic_gpio_get_pin_mode(uint8_t pin) int epic_gpio_get_pin_mode(uint8_t pin)
{ {
if (pin < GPIO_WRISTBAND_1 || pin > GPIO_WRISTBAND_4) if (pin < EPIC_GPIO_WRISTBAND_1 || pin > EPIC_GPIO_WRISTBAND_4)
return -EINVAL; return -EINVAL;
gpio_cfg_t *cfg = &gpio_configs[pin]; gpio_cfg_t *cfg = &gpio_configs[pin];
int res = 0; int res = 0;
if (cfg->func == GPIO_FUNC_IN) if (cfg->func == GPIO_FUNC_IN)
res |= GPIO_MODE_IN; res |= EPIC_GPIO_MODE_IN;
else if (cfg->func == GPIO_FUNC_OUT) else if (cfg->func == GPIO_FUNC_OUT)
res |= GPIO_MODE_OUT; res |= EPIC_GPIO_MODE_OUT;
if (cfg->pad == GPIO_PAD_PULL_UP) if (cfg->pad == GPIO_PAD_PULL_UP)
res |= GPIO_PULL_UP; res |= EPIC_GPIO_PULL_UP;
else if (cfg->pad == GPIO_PAD_PULL_DOWN) else if (cfg->pad == GPIO_PAD_PULL_DOWN)
res |= GPIO_PULL_DOWN; res |= EPIC_GPIO_PULL_DOWN;
return res; return res;
} }
int epic_gpio_write_pin(uint8_t pin, bool on) int epic_gpio_write_pin(uint8_t pin, bool on)
{ {
if (pin < GPIO_WRISTBAND_1 || pin > GPIO_WRISTBAND_4) if (pin < EPIC_GPIO_WRISTBAND_1 || pin > EPIC_GPIO_WRISTBAND_4)
return -EINVAL; return -EINVAL;
gpio_cfg_t *cfg = &gpio_configs[pin]; gpio_cfg_t *cfg = &gpio_configs[pin];
...@@ -86,7 +98,7 @@ int epic_gpio_write_pin(uint8_t pin, bool on) ...@@ -86,7 +98,7 @@ int epic_gpio_write_pin(uint8_t pin, bool on)
int epic_gpio_read_pin(uint8_t pin) int epic_gpio_read_pin(uint8_t pin)
{ {
if (pin < GPIO_WRISTBAND_1 || pin > GPIO_WRISTBAND_4) if (pin < EPIC_GPIO_WRISTBAND_1 || pin > EPIC_GPIO_WRISTBAND_4)
return -EINVAL; return -EINVAL;
gpio_cfg_t *cfg = &gpio_configs[pin]; gpio_cfg_t *cfg = &gpio_configs[pin];
......
...@@ -51,11 +51,13 @@ static MP_DEFINE_CONST_FUN_OBJ_2(gpio_write, mp_gpio_write); ...@@ -51,11 +51,13 @@ static MP_DEFINE_CONST_FUN_OBJ_2(gpio_write, mp_gpio_write);
static const mp_rom_map_elem_t gpio_module_modes_table[] = { static const mp_rom_map_elem_t gpio_module_modes_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mode) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mode) },
{ MP_ROM_QSTR(MP_QSTR_INPUT), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_IN) }, { MP_ROM_QSTR(MP_QSTR_INPUT), MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_MODE_IN) },
{ MP_ROM_QSTR(MP_QSTR_OUTPUT), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OUT) }, { MP_ROM_QSTR(MP_QSTR_OUTPUT),
{ MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_UP) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_MODE_OUT) },
{ MP_ROM_QSTR(MP_QSTR_PULL_UP),
MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_PULL_UP) },
{ MP_ROM_QSTR(MP_QSTR_PULL_DOWN), { MP_ROM_QSTR(MP_QSTR_PULL_DOWN),
MP_OBJ_NEW_SMALL_INT(GPIO_PULL_DOWN) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_PULL_DOWN) },
}; };
static MP_DEFINE_CONST_DICT(gpio_module_modes_dict, gpio_module_modes_table); static MP_DEFINE_CONST_DICT(gpio_module_modes_dict, gpio_module_modes_table);
...@@ -72,13 +74,13 @@ static const mp_rom_map_elem_t gpio_module_globals_table[] = { ...@@ -72,13 +74,13 @@ static const mp_rom_map_elem_t gpio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&gpio_read) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&gpio_read) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&gpio_write) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&gpio_write) },
{ MP_ROM_QSTR(MP_QSTR_WRISTBAND_1), { MP_ROM_QSTR(MP_QSTR_WRISTBAND_1),
MP_OBJ_NEW_SMALL_INT(GPIO_WRISTBAND_1) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_WRISTBAND_1) },
{ MP_ROM_QSTR(MP_QSTR_WRISTBAND_2), { MP_ROM_QSTR(MP_QSTR_WRISTBAND_2),
MP_OBJ_NEW_SMALL_INT(GPIO_WRISTBAND_2) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_WRISTBAND_2) },
{ MP_ROM_QSTR(MP_QSTR_WRISTBAND_3), { MP_ROM_QSTR(MP_QSTR_WRISTBAND_3),
MP_OBJ_NEW_SMALL_INT(GPIO_WRISTBAND_3) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_WRISTBAND_3) },
{ MP_ROM_QSTR(MP_QSTR_WRISTBAND_4), { MP_ROM_QSTR(MP_QSTR_WRISTBAND_4),
MP_OBJ_NEW_SMALL_INT(GPIO_WRISTBAND_4) }, MP_OBJ_NEW_SMALL_INT(EPIC_GPIO_WRISTBAND_4) },
{ MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&gpio_module_modes) }, { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&gpio_module_modes) },
}; };
static MP_DEFINE_CONST_DICT(gpio_module_globals, gpio_module_globals_table); static MP_DEFINE_CONST_DICT(gpio_module_globals, gpio_module_globals_table);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment