f405.c (2063B)
1 /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #include "tractyl_manuform.h" 18 19 #ifdef USB_VBUS_PIN 20 bool usb_vbus_state(void) { 21 gpio_set_pin_input_low(USB_VBUS_PIN); 22 wait_us(5); 23 return gpio_read_pin(USB_VBUS_PIN); 24 } 25 #endif 26 27 #ifdef USER_BUTTON_PIN 28 void user_button_init(void) { 29 // Pin needs to be configured as input low 30 gpio_set_pin_input_low(USER_BUTTON_PIN); 31 } 32 33 bool check_user_button_state(void) { 34 return gpio_read_pin(USER_BUTTON_PIN); 35 } 36 #endif // USER_BUTTON_PIN 37 38 void board_init(void) { 39 // Board setup sets these pins as SPI, but we aren't using them as such. 40 // So to prevent them from misbehaving, we need to set them to a different, non-spi mode. 41 // This is a bit of a hack, but nothing else runs soon enough, without re-implementing spi_init(). 42 gpio_set_pin_input(A5); 43 gpio_set_pin_input(A6); 44 gpio_set_pin_input(A7); 45 46 // If using USB_OTG_HS, we need to set the data pins since they're set wrong for our needs by default. 47 // We set it here by default, in case it's bridged with A11/A12, as to reduce the chance of issues. 48 palSetLineMode( 49 B14, PAL_MODE_ALTERNATE(12) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING); 50 palSetLineMode( 51 B15, PAL_MODE_ALTERNATE(12) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING); 52 }