mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
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:
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#define MCP23017_ADDRESS 0x20
|
#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_test(uint8_t slave);
|
||||||
int mcp23017_toggle(uint8_t slave);
|
int mcp23017_toggle(uint8_t slave);
|
||||||
//int mcp23017_write_byte(uint8_t slave, uint8_t addr, uint8_t byte);
|
//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
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
|
#include <stdbool.h>
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "simtrace.h"
|
#include "simtrace.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@@ -27,6 +28,8 @@
|
|||||||
#include "mcp23017.h"
|
#include "mcp23017.h"
|
||||||
#include "mux.h"
|
#include "mux.h"
|
||||||
|
|
||||||
|
static bool mcp2317_present = false;
|
||||||
|
|
||||||
void board_exec_dbg_cmd(int ch)
|
void board_exec_dbg_cmd(int ch)
|
||||||
{
|
{
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@@ -69,8 +72,9 @@ void board_main_top(void)
|
|||||||
|
|
||||||
mux_init();
|
mux_init();
|
||||||
i2c_pin_init();
|
i2c_pin_init();
|
||||||
if (!mcp23017_init(MCP23017_ADDRESS))
|
/* PORT A: all outputs, Port B0 output, B1..B7 unused */
|
||||||
printf("mcp23017 not found!\n\r");
|
if (mcp23017_init(MCP23017_ADDRESS, 0x00, 0xfe) == 0)
|
||||||
|
mcp2317_present = true;
|
||||||
/* Initialize checking for card insert/remove events */
|
/* Initialize checking for card insert/remove events */
|
||||||
//card_present_init();
|
//card_present_init();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -92,19 +92,25 @@ out_stop:
|
|||||||
return 0;
|
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");
|
printf("mcp23017_init\n\r");
|
||||||
|
|
||||||
// all gpio input
|
// all gpio input
|
||||||
if (mcp23017_write_byte(slave, MCP23017_IODIRA, 0xff))
|
if (mcp23017_write_byte(slave, MCP23017_IODIRA, iodira))
|
||||||
return false;
|
goto out_err;
|
||||||
// msb of portb output, rest input
|
// msb of portb output, rest input
|
||||||
if (mcp23017_write_byte(slave, MCP23017_IODIRB, 0x7f))
|
if (mcp23017_write_byte(slave, MCP23017_IODIRB, iodirb))
|
||||||
return false;
|
goto out_err;
|
||||||
if (mcp23017_write_byte(slave, MCP23017_IOCONA, 0x20)) //disable SEQOP (autoinc addressing)
|
if (mcp23017_write_byte(slave, MCP23017_IOCONA, 0x20)) //disable SEQOP (autoinc addressing)
|
||||||
return false;
|
goto out_err;
|
||||||
|
|
||||||
printf("mcp23017 found\n\r");
|
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)
|
int mcp23017_test(uint8_t slave)
|
||||||
|
|||||||
Reference in New Issue
Block a user