summaryrefslogtreecommitdiffstats
path: root/app/main.c
blob: 11063161f7990b9b3fab6dc5d9a828bd26a35a78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "project.h"

#define WIGGLE	GPIO4
#define WIGGLE_PORT GPIOB

int
main (void)
{
  unsigned cnt = 0;

  //nvic_set_priority_grouping(NVIC_PriorityGroup_4);

  /*set up pll */
  rcc_clock_setup_in_hse_8mhz_out_72mhz ();

  /*turn on clocks which aren't done elsewhere */
  rcc_periph_clock_enable (RCC_GPIOA);
  rcc_periph_clock_enable (RCC_GPIOB);
  rcc_periph_clock_enable (RCC_GPIOC);
  rcc_periph_clock_enable (RCC_AFIO);


  /*Adjust interrupt priorities so that taco trumps uarts trumps timer trumps dma */
  nvic_set_priority (TACHO_IRQ, 0x20);
  nvic_set_priority (NVIC_USART1_IRQ, 0x40);
  nvic_set_priority (NVIC_SYSTICK_IRQ, 0x60);
  nvic_set_priority (NVIC_DMA1_CHANNEL6_IRQ, 0x80);

  /* Claw some pins pack */
  gpio_primary_remap (AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0);

  dwt_enable_cycle_counter ();

  ticker_init ();


  led_init ();
  usart_init ();
  i2cp_init ();

  printf ("Hello world\n");

  led_set ();

  oled_init ();

  tacho_init ();

  font8x8_put_str ("ABC fish soup!", 0, 0);

  MAP_OUTPUT_PP (WIGGLE);


  for (;;)
    {
      char buf[20];

      sprintf (buf, "%6u rpm", (unsigned) raw_tacho);
      font8x16_put_str (buf, 30, 8);

      sprintf (buf, "%8d", cnt++);
      font8x8_put_str (buf, 0, 24);


      if (cnt & 1)
        SET (WIGGLE);
      else
        CLEAR (WIGGLE);

    }

  return 0;
}