~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: 7400879a3e0ad9da11b90d637ac3392ddb1b9691 CTU-FEE-B0B35APO-Semestral-project/lib-pheripherals/src/mzapo_pheripherals.c -rw-r--r-- 2.1 KiB
7400879a — František Boháček feat: add dialog window 3 years ago
                                                                                
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "mzapo_pheripherals.h"
#include "display_utils.h"
#include "mzapo_led_strip.h"
#include "mzapo_phys.h"
#include "mzapo_regs.h"
#include "mzapo_rgb_led.h"
#include <stdlib.h>

mzapo_ledstrip_t mzapo_create_ledstrip() {
  void *pheripherals_base =
      map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0);

  if (pheripherals_base != NULL) {
    pheripherals_base += SPILED_REG_LED_LINE_o;
  }

  return ledstrip_create(pheripherals_base);
}

mzapo_rgb_led_t mzapo_create_rgb_led() {
  void *pheripherals_base =
      map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0);

  if (pheripherals_base != NULL) {
    pheripherals_base += SPILED_REG_LED_RGB1_o;
  }

  return rgb_led_create(pheripherals_base);
}

display_t mzapo_create_display() {
  display_data_t display_data = {
      .base_address =
          map_phys_address(PARLCD_REG_BASE_PHYS, PARLCD_REG_SIZE, 0),
  };

  return display_init(display_data);
}

void *mzapo_get_knobs_address() {
  void *pheripherals_base =
      map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0);

  if (pheripherals_base != NULL) {
    pheripherals_base += SPILED_REG_KNOBS_8BIT_o;
  }

  return pheripherals_base;
}

mzapo_pheripherals_t mzapo_pheripherals_create(mzapo_ledstrip_t *ledstrip,
                               mzapo_rgb_led_t *rgb_led, display_t *display,
                               void **mzapo_knobs_address) {
  mzapo_pheripherals_t pheripherals = {
    .display = display,
    .rgb_leds = rgb_led,
    .ledstrip = ledstrip,
    .knobs = mzapo_knobs_address
  };

  return pheripherals;
}

bool mzapo_check_pheripherals(mzapo_ledstrip_t *ledstrip,
                               mzapo_rgb_led_t *rgb_led, display_t *display,
                               void **mzapo_knobs_address) {
  #ifdef COMPUTER
  return true;
  #endif

  if (ledstrip != NULL && ledstrip->mem_base == NULL) {
    return false;
  }

  if (rgb_led != NULL && rgb_led->mem_base == NULL) {
    return false;
  }

  if (display != NULL && display->data.base_address == NULL) {
    return false;
  }

  if (mzapo_knobs_address != NULL && *mzapo_knobs_address == NULL) {
    return false;
  }

  return true;
}
Do not follow this link