Compare commits
2 commits
5fbc49e6b5
...
a75d940be5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a75d940be5 | ||
|
|
a1ea3d45d5 |
4 changed files with 60 additions and 22 deletions
51
gpio.c
51
gpio.c
|
|
@ -2,23 +2,40 @@
|
|||
#include "gpio.h"
|
||||
#include <lpc2148/gpio.h>
|
||||
|
||||
unsigned int gpio1_mask = 0x00ff0000;
|
||||
unsigned int gpio1_status;
|
||||
|
||||
void gpio_set(unsigned int pins)
|
||||
int gpio1_cmd(struct command *cmd, const struct command_par *par)
|
||||
{
|
||||
pins &= gpio1_mask;
|
||||
GPIO_FIO1SET = pins;
|
||||
GPIO_FIO1DIR |= pins;
|
||||
}
|
||||
void gpio_clr(unsigned int pins)
|
||||
{
|
||||
pins &= gpio1_mask;
|
||||
GPIO_FIO1CLR = pins;
|
||||
GPIO_FIO1DIR |= pins;
|
||||
}
|
||||
unsigned int gpio_read(unsigned int pins)
|
||||
{
|
||||
pins &= gpio1_mask;
|
||||
GPIO_FIO1DIR &=~ pins;
|
||||
return GPIO_FIO1PIN & pins;
|
||||
static const struct keywords gpio_kw[] = {
|
||||
FLAG_VAL("dir", 0x020+2), // GPIO_FIO1DIR2
|
||||
FLAG_VAL("mask", 0x030+2), // GPIO_FIO1MASK2
|
||||
FLAG_VAL("pin", 0x034+2), // GPIO_FIO1PIN2
|
||||
FLAG_VAL("set", 0x038+2), // GPIO_FIO1SET2
|
||||
FLAG_VAL("clr", 0x03C+2), // GPIO_FIO1CLR2
|
||||
{}
|
||||
};
|
||||
|
||||
// syntax example: gpio mask[0xf] dir[0xc] p[0x8] c[0x8]
|
||||
// square brackets are optional where unambiguous
|
||||
|
||||
const struct keywords *k = parse_keyword(cmd, gpio_kw);
|
||||
error_msg_t e = 0;
|
||||
while (k) {
|
||||
if (!k->val)
|
||||
e = &parser_keyword_error;
|
||||
unsigned int val;
|
||||
if (!e)
|
||||
e = parse_expression_square(cmd, &val, 2);
|
||||
if (e)
|
||||
return parser_error_message(cmd, e);
|
||||
BYTE_REG(BASE_FGPIO, k->val) = val;
|
||||
k = parse_keyword(cmd, gpio_kw);
|
||||
}
|
||||
gpio1_status = GPIO_FIO1MASK2 << 24
|
||||
| GPIO_FIO1DIR2 << 16
|
||||
| GPIO_FIO1PINU
|
||||
;
|
||||
parser_format_message(cmd, "%03d GPIO1 0x%08x\n",
|
||||
par->code, gpio1_status);
|
||||
return par->code;
|
||||
}
|
||||
|
|
|
|||
26
gpio.h
26
gpio.h
|
|
@ -91,6 +91,7 @@
|
|||
*/
|
||||
|
||||
#include <lpc2148/gpio.h>
|
||||
#include "parser.h"
|
||||
|
||||
static inline void init_gpio(void) {}
|
||||
|
||||
|
|
@ -100,9 +101,26 @@ static inline void init_gpio(void) {}
|
|||
#define SSP_SSEL_CONF1 0x03ee0000 // ssel bits associated with gpio1 pins
|
||||
#define SSP_MISO (GPIO_FIO0PIN2 & 4)
|
||||
|
||||
extern unsigned int gpio1_mask;
|
||||
void gpio_set(unsigned int pins);
|
||||
void gpio_clr(unsigned int pins);
|
||||
unsigned int gpio_read(unsigned int pins);
|
||||
static inline
|
||||
void gpio_set(unsigned char pins)
|
||||
{
|
||||
GPIO_FIO1SET2 = pins;
|
||||
GPIO_FIO1DIR2 |= pins;
|
||||
}
|
||||
static inline
|
||||
void gpio_clr(unsigned char pins)
|
||||
{
|
||||
GPIO_FIO1CLR2 = pins;
|
||||
GPIO_FIO1DIR2 |= pins;
|
||||
}
|
||||
static inline
|
||||
unsigned char gpio_read(unsigned char pins)
|
||||
{
|
||||
GPIO_FIO1DIR2 &=~ pins;
|
||||
return GPIO_FIO1PIN2 & pins;
|
||||
}
|
||||
|
||||
int gpio1_cmd(struct command *cmd, const struct command_par *par);
|
||||
extern unsigned int gpio1_status;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -520,6 +520,7 @@ static const struct keywords main_command_table[] = {
|
|||
CMD_KW("pressure", pressure_cmd, 366, 0),
|
||||
CMD_KW("bate", bate_cmd, 368, 0),
|
||||
CMD_KW("dac", dac_cmd, 364, 0),
|
||||
CMD_KW("gpio1", gpio1_cmd, 362, 0),
|
||||
CMD_KW("adc", parse_sub_command, 909, adc_commands),
|
||||
CMD_KW("ssp", parse_sub_command, 909, ssp_commands),
|
||||
{"flash", {.par=&flash_command}},
|
||||
|
|
@ -841,6 +842,8 @@ static const struct keywords main_variable_names[] = {
|
|||
VARIABLE("adc_Vp", (unsigned int *)&AD_Vp ),
|
||||
VARIABLE("adc_Vm", (unsigned int *)&AD_Vm ),
|
||||
|
||||
VARIABLE("gpio1", &gpio1_status),
|
||||
|
||||
VARIABLE("revision", &revision),
|
||||
VARIABLE("serial_number", &serial_number),
|
||||
VARIABLE("product", &product),
|
||||
|
|
|
|||
2
ssp.c
2
ssp.c
|
|
@ -684,7 +684,7 @@ int ssp_resp_cmd(struct command *cmd, const struct command_par *par)
|
|||
printf(0, "\n");
|
||||
}
|
||||
|
||||
parser_format_message(cmd, fmt, par->code, nreads,
|
||||
parser_format_message(cmd, fmt, code, nreads,
|
||||
ssp_buffer[0], ssp_buffer[1], ssp_buffer[2], ssp_buffer[3],
|
||||
ssp_buffer[4], ssp_buffer[5], ssp_buffer[6], ssp_buffer[7]);
|
||||
return code;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue