bluepill: start HAL, update skeleton.
This commit is contained in:
54
blue-pill/draugr/bluepill/gpio.h
Normal file
54
blue-pill/draugr/bluepill/gpio.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef __BLUEPILL_GPIO_H__
|
||||
#define __BLUEPILL_GPIO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
constexpr volatile unsigned int *PORTA = reinterpret_cast<volatile unsigned int *>(0x40010800);
|
||||
constexpr volatile unsigned int *PORTB = reinterpret_cast<volatile unsigned int *>(0x40010c00);
|
||||
constexpr volatile unsigned int *PORTC = reinterpret_cast<volatile unsigned int *>(0x40011000);
|
||||
constexpr volatile unsigned int *PORTD = reinterpret_cast<volatile unsigned int *>(0x40011400);
|
||||
constexpr volatile unsigned int *PORTE = reinterpret_cast<volatile unsigned int *>(0x40011800);
|
||||
|
||||
class GPIO {
|
||||
public:
|
||||
void set_pin(uint32_t pin) { this->BSRR |= ((1 << pin) << 16); }
|
||||
void clear_pin(uint32_t pin) { this->BSRR |= (1 << pin); }
|
||||
void output_mode(uint32_t pin, uint32_t mode, uint32_t max) {
|
||||
if (pin > 7) {
|
||||
pin = ((pin - 8) * 4);
|
||||
this->CRH |= (max << pin);
|
||||
this->CRH |= (mode << (pin + 2));
|
||||
}
|
||||
else {
|
||||
pin *= 4;
|
||||
this->CRL |= (max << pin);
|
||||
this->CRL |= (mode << (pin + 2));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t CRL; /* configuration register low */
|
||||
uint32_t CRH; /* configuration register high */
|
||||
uint32_t IDR; /* input data register */
|
||||
uint32_t ODR; /* output data register */
|
||||
uint32_t BSRR; /* bit set / reset register */
|
||||
uint16_t BRR; /* reset register */
|
||||
uint32_t LCKR; /* locking register */
|
||||
};
|
||||
|
||||
GPIO *GPIO_A = (GPIO *)PORTA;
|
||||
GPIO *GPIO_B = (GPIO *)PORTB;
|
||||
GPIO *GPIO_C = (GPIO *)PORTC;
|
||||
GPIO *GPIO_D = (GPIO *)PORTD;
|
||||
GPIO *GPIO_E = (GPIO *)PORTE;
|
||||
const uint32_t OUTPUT_MAX_2MHZ = 2;
|
||||
const uint32_t OUTPUT_MAX_10MHZ = 1;
|
||||
const uint32_t OUTPUT_MAX_50MHZ = 3;
|
||||
const uint32_t OUTPUT_GPP = 0;
|
||||
const uint32_t OUTPUT_GOD = 1;
|
||||
const uint32_t OUTPUT_APP = 2;
|
||||
const uint32_t OUTPUT_AOD = 3;
|
||||
|
||||
|
||||
|
||||
#endif // __BLUEPILL_GPIO_H__
|
||||
6
blue-pill/draugr/bluepill/rcc.h
Normal file
6
blue-pill/draugr/bluepill/rcc.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef __BLUEPILL_RCC_H__
|
||||
#define __BLUEPILL_RCC_H__
|
||||
|
||||
constexpr volatile unsigned int *RCC = reinterpret_cast<volatile unsigned int *>(0x40021000);
|
||||
|
||||
#endif // __BLUEPILL_RCC_H__
|
||||
Reference in New Issue
Block a user