mirror of https://gerrit.osmocom.org/simtrace2
firmware: octsimtest: mcp23017 initializaiton
* driver should not have hard-coded understanding about I/O directions * board code should pass the I/O direction to driver * board code should use the correct I/O directions (A0..7, B0: output) Change-Id: Id4a8e012a33cee01bb489e612e17920760b9be59
This commit is contained in:
parent
d46f6bae2c
commit
dd5794c975
|
@ -18,7 +18,7 @@
|
|||
|
||||
#define MCP23017_ADDRESS 0x20
|
||||
|
||||
int mcp23017_init(uint8_t slave);
|
||||
int mcp23017_init(uint8_t slave, uint8_t iodira, uint8_t iodirb);
|
||||
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);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include "board.h"
|
||||
#include "simtrace.h"
|
||||
#include "utils.h"
|
||||
|
@ -27,6 +28,8 @@
|
|||
#include "mcp23017.h"
|
||||
#include "mux.h"
|
||||
|
||||
static bool mcp2317_present = false;
|
||||
|
||||
void board_exec_dbg_cmd(int ch)
|
||||
{
|
||||
switch (ch) {
|
||||
|
@ -69,8 +72,9 @@ void board_main_top(void)
|
|||
|
||||
mux_init();
|
||||
i2c_pin_init();
|
||||
if (!mcp23017_init(MCP23017_ADDRESS))
|
||||
printf("mcp23017 not found!\n\r");
|
||||
/* PORT A: all outputs, Port B0 output, B1..B7 unused */
|
||||
if (mcp23017_init(MCP23017_ADDRESS, 0x00, 0xfe) == 0)
|
||||
mcp2317_present = true;
|
||||
/* Initialize checking for card insert/remove events */
|
||||
//card_present_init();
|
||||
#endif
|
||||
|
|
|
@ -92,19 +92,25 @@ out_stop:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mcp23017_init(uint8_t slave)
|
||||
int mcp23017_init(uint8_t slave, uint8_t iodira, uint8_t iodirb)
|
||||
{
|
||||
printf("mcp23017_init\n\r");
|
||||
|
||||
// all gpio input
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRA, 0xff))
|
||||
return false;
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRA, iodira))
|
||||
goto out_err;
|
||||
// msb of portb output, rest input
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRB, 0x7f))
|
||||
return false;
|
||||
if (mcp23017_write_byte(slave, MCP23017_IODIRB, iodirb))
|
||||
goto out_err;
|
||||
if (mcp23017_write_byte(slave, MCP23017_IOCONA, 0x20)) //disable SEQOP (autoinc addressing)
|
||||
return false;
|
||||
goto out_err;
|
||||
|
||||
printf("mcp23017 found\n\r");
|
||||
return true;
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("mcp23017 NOT found!\n\r");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mcp23017_test(uint8_t slave)
|
||||
|
|
Loading…
Reference in New Issue