blue-pill: start the startup code

no idea if this works yet
This commit is contained in:
2018-03-07 15:01:27 -08:00
parent 899a1813d1
commit f5621c24b8
6 changed files with 77 additions and 56 deletions

View File

@@ -2,6 +2,7 @@
#define __BLUEPILL_GPIO_H__
#include <stdint.h>
#include "rcc.h"
constexpr volatile unsigned int *PORTA = reinterpret_cast<volatile unsigned int *>(0x40010800);
constexpr volatile unsigned int *PORTB = reinterpret_cast<volatile unsigned int *>(0x40010c00);
@@ -11,21 +12,33 @@ constexpr volatile unsigned int *PORTE = reinterpret_cast<volatile unsigned int
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));
void pin_set(uint32_t pin) { this->BSRR |= ((1 << pin) << 16); }
void pin_clear(uint32_t pin) { this->BSRR |= (1 << pin); }
void pin_mode(uint32_t pin, bool output, uint32_t mode, uint32_t max) {
if (output) {
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));
}
}
}
uint32_t port_index(void) {
/* Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. */
return (((unsigned int)this) - ((unsigned int)PORTA)) >> 10;
}
void enable_clock(void) {
*RCC |= (1 << (this->port_index() + 2));
}
private:
uint32_t CRL; /* configuration register low */
uint32_t CRH; /* configuration register high */