diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 77 |
1 files changed, 74 insertions, 3 deletions
@@ -1,13 +1,29 @@ #include <rcc/rcc.h> #include <os/time.h> +#include <interrupt/interrupt.h> +#include <timer/timer.h> + #include <gpio/gpio.h> #include <usb/usb.h> #include <usb/descriptor.h> +#include "hmc5983.h" + Pin usb_vbus = GPIOB[5]; Pin usb_dm = GPIOA[11]; Pin usb_dp = GPIOA[12]; +Pin spi2_sck = GPIOB[13]; +Pin spi2_miso = GPIOB[14]; +Pin spi2_mosi = GPIOB[15]; +Pin bar_cs = GPIOC[13]; +Pin mag_cs = GPIOC[14]; +Pin mpu_cs = GPIOC[15]; +Pin flash_cs = GPIOB[2]; + +Pin s1 = GPIOA[0]; +Pin s2 = GPIOA[1]; + auto dev_desc = device_desc(0x200, 0, 0, 0, 64, 0x1234, 0x5678, 0, 0, 0, 0, 1); auto conf_desc = configuration_desc(1, 1, 0, 0xc0, 0, interface_desc(1, 0, 1, 0xff, 0x00, 0x00, 0, @@ -41,6 +57,8 @@ class USB_TM : public USB_class_driver { USB_TM usb_tm(usb); +HMC5983 magn(mag_cs, SPI2); + int main() { rcc_init(); @@ -49,6 +67,8 @@ int main() { STK.CTRL = 0x03; RCC.enable(RCC.GPIOA); + RCC.enable(RCC.GPIOB); + RCC.enable(RCC.GPIOC); usb_dm.set_mode(Pin::AF); usb_dm.set_af(14); @@ -56,13 +76,64 @@ int main() { usb_dp.set_af(14); RCC.enable(RCC.USB); - usb.init(); + + //RCC.enable(RCC.SPI2); + /* + spi2_sck.set_mode(Pin::AF); + spi2_sck.set_af(5); + spi2_mosi.set_mode(Pin::AF); + spi2_mosi.set_af(5); + spi2_miso.set_mode(Pin::AF); + spi2_miso.set_af(5); + mag_cs.set_mode(Pin::Output); + mag_cs.on(); + bar_cs.set_mode(Pin::Output); + bar_cs.on(); + mpu_cs.set_mode(Pin::Output); + mpu_cs.on(); + flash_cs.set_mode(Pin::Output); + flash_cs.on(); + + magn.init(); + float buf[3] = {0,0,0}; + */ + s1.set_mode(Pin::AF); + s1.set_af(1); + s2.set_mode(Pin::AF); + s2.set_af(1); + + RCC.enable(RCC.TIM8); + + TIM8.PSC = 168 - 1; + TIM8.ARR = 2500; + TIM8.CCER = (1 << 12) | (1 << 8) | (1 << 4) | (1 << 0); + TIM8.CCMR1 = (6 << 12) | (1 << 11) | (6 << 4) | (1 << 3); + TIM8.CCMR2 = (6 << 12) | (1 << 11) | (6 << 4) | (1 << 3); + TIM8.BDTR = (1 << 15); + TIM8.CCR1 = 1000; + TIM8.CCR2 = 1000; + TIM8.CCR3 = 1000; + TIM8.CCR4 = 1000; + TIM8.CR1 = (1 << 2) | (1 << 0); + while(1) { usb.process(); + //uint8_t magn_status = magn.update(); + + //buf[0] = magn.x; + //buf[1] = magn.y; + //buf[2] = magn.z; + TIM8.CCR1 = 1000 + 100; + TIM8.CCR2 = 1000 + 100; + TIM8.CCR3 = 1000 + 100; + TIM8.CCR4 = 1000 + 100; + + if(usb.ep_ready(1)) { - char a = 'A'; - usb.write(1, (uint32_t*)&a, sizeof(a)); + //usb.write(1, (uint32_t*)&magn.ident, sizeof(magn.ident)); + //usb.write(1, (uint32_t*)buf, sizeof(buf)); + //usb.write(1, (uint32_t*)&magn_status, sizeof(magn_status)); } } }
\ No newline at end of file |