Skip to content

Commit

Permalink
[TractylM] Add F429 configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jan 15, 2025
1 parent 6cecf3e commit bba797b
Show file tree
Hide file tree
Showing 11 changed files with 680 additions and 0 deletions.
23 changes: 23 additions & 0 deletions keyboards/handwired/tractyl_manuform/5x6_right/f429/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2020 Nick Brassel (tzarc)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once

#include_next <board.h>

#undef STM32_HSECLK
#define STM32_HSECLK 8000000U
#undef STM32_LSECLK
#define STM32_LSECLK 32768U
88 changes: 88 additions & 0 deletions keyboards/handwired/tractyl_manuform/5x6_right/f429/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2012 Jun Wako <wakojun@gmail.com>
Copyright 2015 Jack Humbert
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// #define USER_BUTTON_PIN C13
// #define DEBUG_LED_PIN B2

// WS2812 RGB LED strip input and number of LEDs
#define WS2812_PWM_DRIVER PWMD3
#define WS2812_PWM_CHANNEL 1
#define WS2812_PWM_PAL_MODE 2
#define WS2812_PWM_DMA_STREAM STM32_DMA1_STREAM2
#define WS2812_PWM_DMA_CHANNEL 5
#define WS2812_EXTERNAL_PULLUP

#define BACKLIGHT_PWM_DRIVER PWMD8
#define BACKLIGHT_PWM_CHANNEL 3
#define BACKLIGHT_PAL_MODE 3

/* Audio config */
#define AUDIO_PIN A4
#define AUDIO_PIN_ALT A5
#define AUDIO_PIN_ALT_AS_NEGATIVE

/* serial.c configuration for split keyboard */
#define SERIAL_USART_DRIVER SD1
#define SERIAL_USART_TX_PIN B6
#define SERIAL_USART_TX_PAL_MODE 7
#define SERIAL_USART_RX_PIN B7
#define SERIAL_USART_RX_PAL_MODE 7
#define SERIAL_USART_TIMEOUT 10
#define SERIAL_USART_SPEED (1 * 1024 * 1024)
#define SERIAL_USART_FULL_DUPLEX


/* i2c config for oleds */
#define I2C_DRIVER I2CD1
#define I2C1_SCL_PIN B8
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PIN B9
#define I2C1_SDA_PAL_MODE 4
#define I2C1_CLOCK_SPEED 400000
#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_16_9

/* spi config for eeprom and pmw3360 sensor */
#define SPI_DRIVER SPID4
#define SPI_SCK_PIN E2
#define SPI_SCK_PAL_MODE 5
#define SPI_MOSI_PIN E5
#define SPI_MOSI_PAL_MODE 5
#define SPI_MISO_PIN E6
#define SPI_MISO_PAL_MODE 5

#define EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN B13
#define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 4
#define EXTERNAL_FLASH_SIZE (8 * 1024 * 1024)

/* pmw3360 config */
#define POINTING_DEVICE_CS_PIN B5
#define POINTING_DEVICE_ROTATION_270
#undef ROTATIONAL_TRANSFORM_ANGLE
#define PMW33XX_SPI_DIVISOR 16

// lcd
#define DISPLAY_RST_PIN NO_PIN
#define DISPLAY_DC_PIN B12
#define DISPLAY_CS_PIN H12
#define DISPLAY_SPI_DIVIDER 4

#define DRV2605L_FB_ERM_LRA 0
#define DRV2605L_GREETING DRV2605L_EFFECT_750_MS_ALERT_100
#define DRV2605L_DEFAULT_MODE DRV2605L_EFFECT_BUZZ_1_100
195 changes: 195 additions & 0 deletions keyboards/handwired/tractyl_manuform/5x6_right/f429/f429.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tractyl_manuform.h"

#ifdef USB_VBUS_PIN
bool usb_vbus_state(void) {
gpio_set_pin_input_low(USB_VBUS_PIN);
wait_us(5);
return gpio_read_pin(USB_VBUS_PIN);
}
#endif

void user_button_init(void) {
// Pin needs to be configured as input low
#ifdef USER_BUTTON_PIN
gpio_set_pin_input_low(USER_BUTTON_PIN);
#endif // USER_BUTTON_PIN
}

bool check_user_button_state(void) {
#ifdef DEBUG_LED_PIN
gpio_write_pin(DEBUG_LED_PIN, is_keyboard_master());
#endif
#ifdef USER_BUTTON_PIN
return gpio_read_pin(USER_BUTTON_PIN);
#endif // USER_BUTTON_PIN
return false;
}

#if HAL_USE_SDRAM == TRUE
/* SDRAM bank base address.*/
#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000)

/*
* FMC SDRAM Mode definition register defines
*/
#define FMC_SDCMR_MRD_BURST_LENGTH_1 ((uint16_t)0x0000)
#define FMC_SDCMR_MRD_BURST_LENGTH_2 ((uint16_t)0x0001)
#define FMC_SDCMR_MRD_BURST_LENGTH_4 ((uint16_t)0x0002)
#define FMC_SDCMR_MRD_BURST_LENGTH_8 ((uint16_t)0x0004)
#define FMC_SDCMR_MRD_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
#define FMC_SDCMR_MRD_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
#define FMC_SDCMR_MRD_CAS_LATENCY_2 ((uint16_t)0x0020)
#define FMC_SDCMR_MRD_CAS_LATENCY_3 ((uint16_t)0x0030)
#define FMC_SDCMR_MRD_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
#define FMC_SDCMR_MRD_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
#define FMC_SDCMR_MRD_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)

/*
* FMC_ReadPipe_Delay
*/
#define FMC_ReadPipe_Delay_0 ((uint32_t)0x00000000)
#define FMC_ReadPipe_Delay_1 ((uint32_t)0x00002000)
#define FMC_ReadPipe_Delay_2 ((uint32_t)0x00004000)
#define FMC_ReadPipe_Delay_Mask ((uint32_t)0x00006000)

/*
* FMC_Read_Burst
*/
#define FMC_Read_Burst_Disable ((uint32_t)0x00000000)
#define FMC_Read_Burst_Enable ((uint32_t)0x00001000)
#define FMC_Read_Burst_Mask ((uint32_t)0x00001000)

/*
* FMC_SDClock_Period
*/
#define FMC_SDClock_Disable ((uint32_t)0x00000000)
#define FMC_SDClock_Period_2 ((uint32_t)0x00000800)
#define FMC_SDClock_Period_3 ((uint32_t)0x00000C00)
#define FMC_SDClock_Period_Mask ((uint32_t)0x00000C00)

/*
* FMC_ColumnBits_Number
*/
#define FMC_ColumnBits_Number_8b ((uint32_t)0x00000000)
#define FMC_ColumnBits_Number_9b ((uint32_t)0x00000001)
#define FMC_ColumnBits_Number_10b ((uint32_t)0x00000002)
#define FMC_ColumnBits_Number_11b ((uint32_t)0x00000003)

/*
* FMC_RowBits_Number
*/
#define FMC_RowBits_Number_11b ((uint32_t)0x00000000)
#define FMC_RowBits_Number_12b ((uint32_t)0x00000004)
#define FMC_RowBits_Number_13b ((uint32_t)0x00000008)

/*
* FMC_SDMemory_Data_Width
*/
#define FMC_SDMemory_Width_8b ((uint32_t)0x00000000)
#define FMC_SDMemory_Width_16b ((uint32_t)0x00000010)
#define FMC_SDMemory_Width_32b ((uint32_t)0x00000020)

/*
* FMC_InternalBank_Number
*/
#define FMC_InternalBank_Number_2 ((uint32_t)0x00000000)
#define FMC_InternalBank_Number_4 ((uint32_t)0x00000040)

/*
* FMC_CAS_Latency
*/
#define FMC_CAS_Latency_1 ((uint32_t)0x00000080)
#define FMC_CAS_Latency_2 ((uint32_t)0x00000100)
#define FMC_CAS_Latency_3 ((uint32_t)0x00000180)

/*
* FMC_Write_Protection
*/
#define FMC_Write_Protection_Disable ((uint32_t)0x00000000)
#define FMC_Write_Protection_Enable ((uint32_t)0x00000200)

#include "hal.h"

/*
* SDRAM driver configuration structure.
*/
static const SDRAMConfig sdram_cfg = {
.sdcr = (uint32_t)(FMC_ColumnBits_Number_8b |
FMC_RowBits_Number_12b |
FMC_SDMemory_Width_16b |
FMC_InternalBank_Number_4 |
FMC_CAS_Latency_3 |
FMC_Write_Protection_Disable |
FMC_SDClock_Period_2 |
FMC_Read_Burst_Disable |
FMC_ReadPipe_Delay_1),

.sdtr = (uint32_t)((2 - 1) | // FMC_LoadToActiveDelay = 2 (TMRD: 2 Clock cycles)
(7 << 4) | // FMC_ExitSelfRefreshDelay = 7 (TXSR: min=70ns (7x11.11ns))
(4 << 8) | // FMC_SelfRefreshTime = 4 (TRAS: min=42ns (4x11.11ns) max=120k (ns))
(7 << 12) | // FMC_RowCycleDelay = 7 (TRC: min=70 (7x11.11ns))
(2 << 16) | // FMC_WriteRecoveryTime = 2 (TWR: min=1+ 7ns (1+1x11.11ns))
(2 << 20) | // FMC_RPDelay = 2 (TRP: 20ns => 2x11.11ns)
(2 << 24)), // FMC_RCDDelay = 2 (TRCD: 20ns => 2x11.11ns)

.sdcmr = (uint32_t)(((4 - 1) << 5) |
((FMC_SDCMR_MRD_BURST_LENGTH_2 |
FMC_SDCMR_MRD_BURST_TYPE_SEQUENTIAL |
FMC_SDCMR_MRD_CAS_LATENCY_3 |
FMC_SDCMR_MRD_OPERATING_MODE_STANDARD |
FMC_SDCMR_MRD_WRITEBURST_MODE_SINGLE) << 9)),

/* if (STM32_SYSCLK == 180000000) ->
64ms / 4096 = 15.625us
15.625us * 90MHz = 1406 - 20 = 1386 */
//.sdrtr = (1386 << 1),
.sdrtr = (uint32_t)(683 << 1),
};

/* SDRAM size, in bytes.*/
#define IS42S16400J_SIZE (8 * 1024 * 1024)

/*
* Erases the whole SDRAM bank.
*/
static void sdram_bulk_erase(void) {

volatile uint8_t *p = (volatile uint8_t *)SDRAM_BANK_ADDR;
volatile uint8_t *end = p + IS42S16400J_SIZE;
while (p < end)
*p++ = 0;
}

void board_init(void) {


/*
* Initialise FSMC for SDRAM.
*/
sdramInit();
sdramStart(&SDRAMD1, &sdram_cfg);
sdram_bulk_erase();
// // Board setup sets these pins as SPI, but we aren't using them as such.
// // So to prevent them from misbehaving, we need to set them to a different, non-spi mode.
// // This is a bit of a hack, but nothing else runs soon enough, without re-implementing spi_init().
// gpio_set_pin_input(A5);
// gpio_set_pin_input(A6);
// gpio_set_pin_input(A7);
}
#endif
36 changes: 36 additions & 0 deletions keyboards/handwired/tractyl_manuform/5x6_right/f429/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2020 Nick Brassel (tzarc)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once

#define HAL_USE_SERIAL TRUE
#define SERIAL_BUFFERS_SIZE 256

#if defined(WS2812_PWM) || defined(BACKLIGHT_PWM)
# define HAL_USE_PWM TRUE
#endif // defined(WS2812_PWM) || defined(BACKLIGHT_PWM)

#if HAL_USE_SPI == TRUE
# define SPI_USE_WAIT TRUE
# define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#endif

#ifdef AUDIO_DRIVER_DAC
# define HAL_USE_GPT TRUE
# define HAL_USE_DAC TRUE
#endif

#include_next <halconf.h>
#include "halconf_community.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright 2020 Nick Brassel (tzarc)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once

#define HAL_USE_COMMUNITY TRUE
#define HAL_USE_FSMC TRUE
#define HAL_USE_SDRAM TRUE
#define HAL_USE_CRC FALSE
#define HAL_USE_RNG FALSE
#define HAL_USE_USBH FALSE

#include_next <halconf_community.h>
Loading

0 comments on commit bba797b

Please sign in to comment.