laforge has submitted this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24534 )
Change subject: firmware: octsimtest: mcp23017 initializaiton ...................................................................... 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 --- M firmware/libboard/octsimtest/include/mcp23017.h M firmware/libboard/octsimtest/source/board_octsimtest.c M firmware/libboard/octsimtest/source/mcp23017.c 3 files changed, 20 insertions(+), 10 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/firmware/libboard/octsimtest/include/mcp23017.h b/firmware/libboard/octsimtest/include/mcp23017.h index 962a1d5..c0f4b13 100644 --- a/firmware/libboard/octsimtest/include/mcp23017.h +++ b/firmware/libboard/octsimtest/include/mcp23017.h @@ -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); diff --git a/firmware/libboard/octsimtest/source/board_octsimtest.c b/firmware/libboard/octsimtest/source/board_octsimtest.c index 85d8aab..404bef6 100644 --- a/firmware/libboard/octsimtest/source/board_octsimtest.c +++ b/firmware/libboard/octsimtest/source/board_octsimtest.c @@ -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 @@ 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 diff --git a/firmware/libboard/octsimtest/source/mcp23017.c b/firmware/libboard/octsimtest/source/mcp23017.c index 167bf34..a4d055f 100644 --- a/firmware/libboard/octsimtest/source/mcp23017.c +++ b/firmware/libboard/octsimtest/source/mcp23017.c @@ -92,19 +92,25 @@ 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) -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24534 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: Id4a8e012a33cee01bb489e612e17920760b9be59 Gerrit-Change-Number: 24534 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <lafo...@osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <lafo...@osmocom.org> Gerrit-MessageType: merged