mirror of https://gerrit.osmocom.org/simtrace2
add/fix mcp23017 i2c gpio expander functions and tests
Change-Id: Ia2e5a1bf3f97272931014e54e587109297556c03
This commit is contained in:
parent
3feadfa910
commit
f7f1ea864d
|
@ -2,9 +2,7 @@
|
|||
#include "utils.h"
|
||||
#include "chip.h"
|
||||
|
||||
|
||||
|
||||
void gpio_test_init(void)
|
||||
{
|
||||
printf("FIXME run tests here\n\n");
|
||||
printf("FIXME run tests here\n\r");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ void i2c_pin_init(void);
|
|||
|
||||
bool i2c_write_byte(bool send_start, bool send_stop, uint8_t byte);
|
||||
uint8_t i2c_read_byte(bool nack, bool send_stop);
|
||||
static void i2c_stop_cond(void);
|
||||
void i2c_stop_cond(void);
|
||||
|
||||
int eeprom_write_byte(uint8_t slave, uint8_t addr, uint8_t byte);
|
||||
int eeprom_read_byte(uint8_t slave, uint8_t addr);
|
||||
|
|
|
@ -19,5 +19,7 @@
|
|||
#define MCP23017_ADDRESS 0x20
|
||||
|
||||
int mcp23017_init(uint8_t slave);
|
||||
int mcp23017_test(uint8_t slave);
|
||||
int mcp23017_toggle(uint8_t slave);
|
||||
//int mcp23017_write_byte(uint8_t slave, uint8_t addr, uint8_t byte);
|
||||
//int mcp23017_read_byte(uint8_t slave, uint8_t addr);
|
||||
|
|
|
@ -32,12 +32,20 @@ void board_exec_dbg_cmd(int ch)
|
|||
case '?':
|
||||
printf("\t?\thelp\n\r");
|
||||
printf("\tR\treset SAM3\n\r");
|
||||
printf("\tm\trun mcp23017 test\n\r");
|
||||
printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
|
||||
break;
|
||||
case 'R':
|
||||
printf("Asking NVIC to reset us\n\r");
|
||||
USBD_Disconnect();
|
||||
NVIC_SystemReset();
|
||||
break;
|
||||
case 'm':
|
||||
mcp23017_test(MCP23017_ADDRESS);
|
||||
break;
|
||||
case 't':
|
||||
mcp23017_toggle(MCP23017_ADDRESS);
|
||||
break;
|
||||
default:
|
||||
printf("Unknown command '%c'\n\r", ch);
|
||||
break;
|
||||
|
@ -50,7 +58,8 @@ void board_main_top(void)
|
|||
usb_buf_init();
|
||||
|
||||
i2c_pin_init();
|
||||
mcp23017_init(MCP23017_ADDRESS);
|
||||
if (!mcp23017_init(MCP23017_ADDRESS))
|
||||
printf("mcp23017 not found!\n\r");
|
||||
/* Initialize checking for card insert/remove events */
|
||||
//card_present_init();
|
||||
#endif
|
||||
|
|
|
@ -96,7 +96,7 @@ static void i2c_start_cond(void)
|
|||
i2c_started = true;
|
||||
}
|
||||
|
||||
static void i2c_stop_cond(void)
|
||||
void i2c_stop_cond(void)
|
||||
{
|
||||
clear_sda();
|
||||
set_scl();
|
||||
|
|
|
@ -94,13 +94,47 @@ out_stop:
|
|||
|
||||
int mcp23017_init(uint8_t slave)
|
||||
{
|
||||
printf("mcp23017_init\n");
|
||||
printf("mcp23017_init\n\r");
|
||||
// all gpio input
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRA, 0xff))
|
||||
return false;
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRB, 0xff))
|
||||
// msb of portb output, rest input
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRB, 0x7f))
|
||||
return false;
|
||||
printf("mcp23017 found\n");
|
||||
if (mcp23017_write_byte(slave, MCP23017_IOCONA, 0x20)) //disable SEQOP (autoinc addressing)
|
||||
return false;
|
||||
printf("mcp23017 found\n\r");
|
||||
return true;
|
||||
}
|
||||
|
||||
int mcp23017_test(uint8_t slave)
|
||||
{
|
||||
printf("mcp23017_test\n\r");
|
||||
printf("GPIOA 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_GPIOA));
|
||||
printf("GPIOB 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_GPIOB));
|
||||
printf("IODIRA 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_IODIRA));
|
||||
printf("IODIRB 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_IODIRB));
|
||||
printf("IOCONA 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_IOCONA));
|
||||
printf("IOCONB 0x%x\n\r", mcp23017_read_byte(slave,MCP23017_IOCONB));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mcp23017_toggle(uint8_t slave)
|
||||
{
|
||||
// example writing MSB of gpio
|
||||
static bool foo=false;
|
||||
if (foo)
|
||||
{
|
||||
printf("+\n\r");
|
||||
mcp23017_write_byte(slave, MCP23017_OLATB, 0x80);
|
||||
foo=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-\n\r");
|
||||
mcp23017_write_byte(slave, MCP23017_OLATB, 0x00);
|
||||
foo=true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue