Use new LED pins

This commit is contained in:
fruchti 2021-04-04 20:52:15 +02:00
parent 64a01bef05
commit a900c9481d
6 changed files with 46 additions and 15 deletions

View file

@ -1 +1 @@
322
325

View file

@ -1,15 +1,18 @@
#include "led.h"
#include "ownership.h"
MODULE_OWNS_PIN(GPIOB, PIN_LED);
MODULE_OWNS_PIN(GPIOA, PIN_LED_PINK);
MODULE_OWNS_PIN(GPIOA, PIN_LED_ORANGE);
void LED_Init(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
GPIOC->CRH = (GPIOB->CRH
& ~(0x0f << (PIN_LED * 4 - 32)))
| (0x02 << (PIN_LED * 4 - 32)) // 2 MHz push-pull output
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
GPIOA->CRL = (GPIOA->CRL
& ~(0x0f << (PIN_LED_PINK * 4))
& ~(0x0f << (PIN_LED_ORANGE * 4)))
| (0x02 << (PIN_LED_PINK * 4)) // 2 MHz push-pull output
| (0x02 << (PIN_LED_ORANGE * 4)) // 2 MHz push-pull output
;
}

View file

@ -3,8 +3,37 @@
#include "stm32f1xx.h"
#include "pinning.h"
#define LED_ON() do { GPIOC->BRR = 1 << PIN_LED; } while(0);
#define LED_OFF() do { GPIOC->BSRR = 1 << PIN_LED; } while(0);
typedef enum
{
LED_Pink,
LED_Orange
} LED_t;
inline void LED_On(LED_t led)
{
switch(led)
{
case LED_Pink:
GPIOA->BSRR = 1 << PIN_LED_PINK;
break;
case LED_Orange:
GPIOA->BSRR = 1 << PIN_LED_ORANGE;
break;
}
}
inline void LED_Off(LED_t led)
{
switch(led)
{
case LED_Pink:
GPIOA->BRR = 1 << PIN_LED_PINK;
break;
case LED_Orange:
GPIOA->BRR = 1 << PIN_LED_ORANGE;
break;
}
}
void LED_Init(void);

View file

@ -40,7 +40,7 @@ int main(void)
USB_Init();
Output_Init();
LED_ON();
LED_On(LED_Orange);
// uint8_t buffer[32];
for(;;)

View file

@ -1,15 +1,14 @@
#pragma once
// Port A
#define PIN_OUTPUT_ENABLE 3 // PA3 - Relay coil driver
#define PIN_LED_PINK 6 // PA6 - Status LED 1
#define PIN_LED_ORANGE 7 // PA7 - Status LED 2
#define PIN_OUTPUT_X 8 // PA8 - TIM1_CH1
#define PIN_OUTPUT_Y 9 // PA9 - TIM1_CH2
#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 - TIM4_CH1
// Port C
#define PIN_LED 13 // PC13 - Status LED

View file

@ -72,7 +72,7 @@ static inline void USB_HandleReset(void)
// Enable
USB->DADDR = USB_DADDR_EF;
LED_OFF();
LED_Off(LED_Orange);
}
static inline void USB_HandleIn(void)