Use PB6 for pen state output

This commit is contained in:
fruchti 2020-12-25 14:23:55 +01:00
parent 8b1ead2c89
commit a529996719
3 changed files with 14 additions and 8 deletions

View file

@ -1 +1 @@
280 281

View file

@ -3,11 +3,13 @@
// Port A // Port A
#define PIN_OUTPUT_X 8 // PA8 - TIM1_CH1 #define PIN_OUTPUT_X 8 // PA8 - TIM1_CH1
#define PIN_OUTPUT_Y 9 // PA9 - TIM1_CH2 #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_DM 11 // PA11 - USB_DM
#define PIN_USB_DP 12 // PA12 - USB_DP #define PIN_USB_DP 12 // PA12 - USB_DP
// #define PIN_USB_PULLUP 15 // PA15 - 1.5 kΩ to D+ // #define PIN_USB_PULLUP 15 // PA15 - 1.5 kΩ to D+
// Port B
#define PIN_PEN_STATE 6 // PB6
// Port C // Port C
#define PIN_LED 13 // PC13 - Status LED #define PIN_LED 13 // PC13 - Status LED

View file

@ -7,7 +7,7 @@
MODULE_OWNS_PIN(GPIOA, PIN_OUTPUT_X); MODULE_OWNS_PIN(GPIOA, PIN_OUTPUT_X);
MODULE_OWNS_PIN(GPIOA, PIN_OUTPUT_Y); 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); MODULE_OWNS_PERIPHERAL(TIM1);
static HPGL_Movement_t Output_Buffer[CONFIG_BUFFER_MOVEMENTS]; 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) static void Output_PenDown(void)
{ {
GPIOA->BRR = (1 << PIN_PEN_STATE); GPIOB->BRR = (1 << PIN_PEN_STATE);
Output_PenIsDown = true; Output_PenIsDown = true;
} }
static void Output_PenUp(void) static void Output_PenUp(void)
{ {
GPIOA->BSRR = (1 << PIN_PEN_STATE); GPIOB->BSRR = (1 << PIN_PEN_STATE);
Output_PenIsDown = false; Output_PenIsDown = false;
} }
@ -189,16 +189,20 @@ void Output_Init(void)
{ {
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
Output_PenUp(); Output_PenUp();
GPIOA->CRH = (GPIOA->CRH GPIOA->CRH = (GPIOA->CRH
& ~(0xf << (4 * PIN_OUTPUT_X - 32)) & ~(0xf << (4 * PIN_OUTPUT_X - 32))
& ~(0xf << (4 * PIN_OUTPUT_Y - 32)) & ~(0xf << (4 * PIN_OUTPUT_Y - 32)))
& ~(0xf << (4 * PIN_PEN_STATE - 32)))
| (0xa << (4 * PIN_OUTPUT_X - 32)) // AF output, 2 MHz | (0xa << (4 * PIN_OUTPUT_X - 32)) // AF output, 2 MHz
| (0xa << (4 * PIN_OUTPUT_Y - 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 TIM1->CCMR1 = TIM_CCMR1_OC1PE | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1