summaryrefslogtreecommitdiffstats
path: root/radiator-plc/stm32/app/outputs.c
blob: 67d051925b3e4a237af18d6f19c58bc126481f16 (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
#include "project.h"

#define N_OUTPUTS 8

static const uint32_t output_bank[N_OUTPUTS] = { GPIOC, GPIOA, GPIOA, GPIOA, GPIOD, GPIOD, GPIOD, GPIOD};
static const uint32_t output[N_OUTPUTS] = { GPIO9, GPIO8, GPIO11, GPIO12, GPIO0, GPIO1, GPIO2, GPIO3};

void output_set (unsigned r)
{
  if (r >= N_OUTPUTS) return;

  gpio_set (output_bank[r], output[r]);
}

void output_clear (unsigned r)
{
  if (r >= N_OUTPUTS) return;

  gpio_clear (output_bank[r], output[r]);
}

void outputs_set (unsigned v)
{
  unsigned r;

  for (r = 0; r < N_OUTPUTS; r++, v >>= 1) {
    if (v & 1) output_set (r);
    else output_clear (r);
  }
}

void output_write (unsigned r, unsigned v)
{
  if (v) output_set (r);
  else output_clear (r);
}



void outputs_init (void)
{
  unsigned r;

  for (r = 0; r < N_OUTPUTS; ++r)
    gpio_set_mode (output_bank[r], GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, output[r]);

}