From a52999671920a4bca0864cada537839f34fd5a6b Mon Sep 17 00:00:00 2001 From: fruchti Date: Fri, 25 Dec 2020 14:23:55 +0100 Subject: [PATCH] Use PB6 for pen state output --- stm32f103c8t6/build_number.txt | 2 +- stm32f103c8t6/src/pinning.h | 4 +++- stm32f103c8t6/src/pwm_output.c | 16 ++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/stm32f103c8t6/build_number.txt b/stm32f103c8t6/build_number.txt index 1b1c131..1473a88 100644 --- a/stm32f103c8t6/build_number.txt +++ b/stm32f103c8t6/build_number.txt @@ -1 +1 @@ -280 +281 diff --git a/stm32f103c8t6/src/pinning.h b/stm32f103c8t6/src/pinning.h index 864bbf5..11f3820 100644 --- a/stm32f103c8t6/src/pinning.h +++ b/stm32f103c8t6/src/pinning.h @@ -3,11 +3,13 @@ // Port A #define PIN_OUTPUT_X 8 // PA8 - TIM1_CH1 #define PIN_OUTPUT_Y 9 // PA9 - TIM1_CH2 -#define PIN_PEN_STATE 10 // PA10 #define PIN_USB_DM 11 // PA11 - USB_DM #define PIN_USB_DP 12 // PA12 - USB_DP // #define PIN_USB_PULLUP 15 // PA15 - 1.5 kΩ to D+ +// Port B +#define PIN_PEN_STATE 6 // PB6 + // Port C #define PIN_LED 13 // PC13 - Status LED diff --git a/stm32f103c8t6/src/pwm_output.c b/stm32f103c8t6/src/pwm_output.c index 708f1dc..ae47f05 100644 --- a/stm32f103c8t6/src/pwm_output.c +++ b/stm32f103c8t6/src/pwm_output.c @@ -7,7 +7,7 @@ MODULE_OWNS_PIN(GPIOA, PIN_OUTPUT_X); MODULE_OWNS_PIN(GPIOA, PIN_OUTPUT_Y); -MODULE_OWNS_PIN(GPIOA, PIN_PEN_STATE); +MODULE_OWNS_PIN(GPIOB, PIN_PEN_STATE); MODULE_OWNS_PERIPHERAL(TIM1); static HPGL_Movement_t Output_Buffer[CONFIG_BUFFER_MOVEMENTS]; @@ -60,13 +60,13 @@ bool Output_EnqueueMovement(HPGL_Movement_t movement) static void Output_PenDown(void) { - GPIOA->BRR = (1 << PIN_PEN_STATE); + GPIOB->BRR = (1 << PIN_PEN_STATE); Output_PenIsDown = true; } static void Output_PenUp(void) { - GPIOA->BSRR = (1 << PIN_PEN_STATE); + GPIOB->BSRR = (1 << PIN_PEN_STATE); Output_PenIsDown = false; } @@ -189,16 +189,20 @@ void Output_Init(void) { RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; + RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; Output_PenUp(); GPIOA->CRH = (GPIOA->CRH & ~(0xf << (4 * PIN_OUTPUT_X - 32)) - & ~(0xf << (4 * PIN_OUTPUT_Y - 32)) - & ~(0xf << (4 * PIN_PEN_STATE - 32))) + & ~(0xf << (4 * PIN_OUTPUT_Y - 32))) | (0xa << (4 * PIN_OUTPUT_X - 32)) // AF output, 2 MHz | (0xa << (4 * PIN_OUTPUT_Y - 32)) // AF output, 2 MHz - | (0x6 << (4 * PIN_PEN_STATE - 32)) // OD output, 2 MHz + ; + + GPIOB->CRL = (GPIOB->CRL + & ~(0xf << (4 * PIN_PEN_STATE))) + | (0x6 << (4 * PIN_PEN_STATE)) // OD output, 2 MHz ; TIM1->CCMR1 = TIM_CCMR1_OC1PE | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1