blob: b7d7245cec63d7304531eafe58444ccbc4c1bb2b [file] [log] [blame]
Joachim Steigerb1a81c12019-07-26 22:13:51 +02001/* SIMtrace with SAM3S specific application code
2 *
3 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19 */
20#include "board.h"
21#include "simtrace.h"
22#include "utils.h"
23#include "sim_switch.h"
24#include <osmocom/core/timer.h>
25#include "usb_buf.h"
26#include "i2c.h"
27#include "mcp23017.h"
28
29void board_exec_dbg_cmd(int ch)
30{
31 switch (ch) {
32 case '?':
33 printf("\t?\thelp\n\r");
34 printf("\tR\treset SAM3\n\r");
Joachim Steigerf7f1ea82019-10-24 18:09:05 +020035 printf("\tm\trun mcp23017 test\n\r");
36 printf("\tR\ttoggle MSB of gpio on mcp23017\n\r");
Joachim Steigerb1a81c12019-07-26 22:13:51 +020037 break;
38 case 'R':
39 printf("Asking NVIC to reset us\n\r");
40 USBD_Disconnect();
41 NVIC_SystemReset();
42 break;
Joachim Steigerf7f1ea82019-10-24 18:09:05 +020043 case 'm':
44 mcp23017_test(MCP23017_ADDRESS);
45 break;
46 case 't':
47 mcp23017_toggle(MCP23017_ADDRESS);
48 break;
Joachim Steigerb1a81c12019-07-26 22:13:51 +020049 default:
50 printf("Unknown command '%c'\n\r", ch);
51 break;
52 }
53}
54
55void board_main_top(void)
56{
57#ifndef APPLICATION_dfu
58 usb_buf_init();
59
60 i2c_pin_init();
Joachim Steigerf7f1ea82019-10-24 18:09:05 +020061 if (!mcp23017_init(MCP23017_ADDRESS))
62 printf("mcp23017 not found!\n\r");
Joachim Steigerb1a81c12019-07-26 22:13:51 +020063 /* Initialize checking for card insert/remove events */
64 //card_present_init();
65#endif
66}
67
68int board_override_enter_dfu(void)
69{
70 const Pin bl_sw_pin = PIN_BOOTLOADER_SW;
71
72 PIO_Configure(&bl_sw_pin, 1);
73
74 /* Enter DFU bootloader in case the respective button is pressed */
75 if (PIO_Get(&bl_sw_pin) == 0) {
76 /* do not print to early since the console is not initialized yet */
77 //printf("BOOTLOADER switch pressed -> Force DFU\n\r");
78 return 1;
79 } else
80 return 0;
81}