|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Copyright Christopher Kormanyos 2025. |
| 3 | +// Distributed under the Boost Software License, |
| 4 | +// Version 1.0. (See accompanying file LICENSE_1_0.txt |
| 5 | +// or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | +// |
| 7 | + |
| 8 | +#ifndef MCAL_LED_AM6254_SOC_2025_08_04_H |
| 9 | + #define MCAL_LED_AM6254_SOC_2025_08_04_H |
| 10 | + |
| 11 | + #include <mcal_led/mcal_led_boolean_state_base.h> |
| 12 | + |
| 13 | + #include <util/utility/util_time.h> |
| 14 | + |
| 15 | + #include <cstdint> |
| 16 | + |
| 17 | + #define PADCFG_CTRL0_CFG0_PADCONFIG3 UINT32_C(0x000F400C) |
| 18 | + #define PADCFG_CTRL0_CFG0_PADCONFIG4 UINT32_C(0x000F4010) |
| 19 | + #define PADCFG_CTRL0_CFG0_PADCONFIG5 UINT32_C(0x000F4014) |
| 20 | + #define PADCFG_CTRL0_CFG0_PADCONFIG6 UINT32_C(0x000F4018) |
| 21 | + |
| 22 | + #define GPIO_DIR01 UINT32_C(0x00600010) |
| 23 | + #define GPIO_OUT_DATA01 UINT32_C(0x00600014) |
| 24 | + #define GPIO_SET_DATA01 UINT32_C(0x00600018) |
| 25 | + #define GPIO_CLR_DATA01 UINT32_C(0x0060001C) |
| 26 | + |
| 27 | + #define LED_1 6 |
| 28 | + #define LED_2 5 |
| 29 | + #define LED_3 4 |
| 30 | + #define LED_4 3 |
| 31 | + |
| 32 | + #define LED_INIT() do{ \ |
| 33 | + *(volatile uint32_t*)(PADCFG_CTRL0_CFG0_PADCONFIG3) &= ~((uint32_t)1ul <<21); \ |
| 34 | + *(volatile uint32_t*)(PADCFG_CTRL0_CFG0_PADCONFIG4) &= ~((uint32_t)1ul <<21); \ |
| 35 | + *(volatile uint32_t*)(PADCFG_CTRL0_CFG0_PADCONFIG5) &= ~((uint32_t)1ul <<21); \ |
| 36 | + *(volatile uint32_t*)(PADCFG_CTRL0_CFG0_PADCONFIG6) &= ~((uint32_t)1ul <<21); \ |
| 37 | + *(volatile uint32_t*)(GPIO_DIR01) &= ~((uint32_t)0x78ul); \ |
| 38 | + *(volatile uint32_t*)(GPIO_CLR_DATA01) |= 0x78; \ |
| 39 | + *(volatile uint32_t*)(GPIO_OUT_DATA01) &= ~((uint32_t)0x78ul); \ |
| 40 | + }while(0) |
| 41 | + |
| 42 | + #define LED_ON(x) do{*(volatile uint32_t*)(GPIO_SET_DATA01) |= (1ul << x); *(volatile uint32_t*)(GPIO_OUT_DATA01) |= (1ul << x);}while(0) |
| 43 | + #define LED_OFF(x) do{*(volatile uint32_t*)(GPIO_CLR_DATA01) |= (1ul << x); *(volatile uint32_t*)(GPIO_OUT_DATA01) &= (uint32_t)(~(uint32_t)(1ul << x));}while(0) |
| 44 | + |
| 45 | + #define LED_1_ON() LED_ON(LED_1) |
| 46 | + #define LED_2_ON() LED_ON(LED_2) |
| 47 | + #define LED_3_ON() LED_ON(LED_3) |
| 48 | + #define LED_4_ON() LED_ON(LED_4) |
| 49 | + |
| 50 | + #define LED_1_OFF() LED_OFF(LED_1) |
| 51 | + #define LED_2_OFF() LED_OFF(LED_2) |
| 52 | + #define LED_3_OFF() LED_OFF(LED_3) |
| 53 | + #define LED_4_OFF() LED_OFF(LED_4) |
| 54 | + |
| 55 | + namespace mcal |
| 56 | + { |
| 57 | + namespace led |
| 58 | + { |
| 59 | + template<typename VoidClass> |
| 60 | + class led_am6254_soc_base : public mcal::led::led_boolean_state_base |
| 61 | + { |
| 62 | + public: |
| 63 | + ~led_am6254_soc_base() override = default; |
| 64 | + |
| 65 | + protected: |
| 66 | + led_am6254_soc_base() noexcept = default; |
| 67 | + |
| 68 | + auto toggle() -> void override |
| 69 | + { |
| 70 | + using base_class_type = led_boolean_state_base; |
| 71 | + |
| 72 | + base_class_type::toggle(); |
| 73 | + } |
| 74 | + |
| 75 | + private: |
| 76 | + static const bool is_init; |
| 77 | + }; |
| 78 | + |
| 79 | + template<typename VoidClass> |
| 80 | + const bool led_am6254_soc_base<VoidClass>::is_init = []() { LED_INIT(); return true; }(); |
| 81 | + |
| 82 | + template<const int LED_ID> |
| 83 | + class led_am6254_soc final : public mcal::led::led_am6254_soc_base<void> |
| 84 | + { |
| 85 | + public: |
| 86 | + led_am6254_soc() noexcept = default; |
| 87 | + |
| 88 | + ~led_am6254_soc() override = default; |
| 89 | + |
| 90 | + auto toggle() -> void override |
| 91 | + { |
| 92 | + using base_class_type = led_am6254_soc_base<void>; |
| 93 | + |
| 94 | + if(base_class_type::state_is_on()) |
| 95 | + { |
| 96 | + LED_OFF(LED_ID); |
| 97 | + } |
| 98 | + else |
| 99 | + { |
| 100 | + LED_ON(LED_ID); |
| 101 | + } |
| 102 | + |
| 103 | + base_class_type::toggle(); |
| 104 | + } |
| 105 | + }; |
| 106 | + |
| 107 | + template<const int LED_ID> |
| 108 | + static void main_core_worker(void) |
| 109 | + { |
| 110 | + using timer_type = util::timer<std::uint64_t>; |
| 111 | + |
| 112 | + using led_type = led_am6254_soc<LED_ID>; |
| 113 | + |
| 114 | + led_type my_led; |
| 115 | + |
| 116 | + timer_type led_timer(timer_type::seconds(1U)); |
| 117 | + |
| 118 | + my_led.toggle(); |
| 119 | + |
| 120 | + for(;;) |
| 121 | + { |
| 122 | + while(!led_timer.timeout()) { asm volatile("nop"); } |
| 123 | + |
| 124 | + my_led.toggle(); |
| 125 | + |
| 126 | + led_timer.start_interval(timer_type::seconds(1U)); |
| 127 | + } |
| 128 | + } |
| 129 | + } // namespace led |
| 130 | + } // namespace mcal |
| 131 | + |
| 132 | +#endif // MCAL_LED_AM6254_SOC_2025_08_04_H |
0 commit comments