1+ #ifndef KLIB_LPC1754_CAN_HPP
2+ #define KLIB_LPC1754_CAN_HPP
3+
4+ #include < cstdint>
5+
6+ #include < targets/core/nxp/lpc175x/can.hpp>
7+ #include " pins.hpp"
8+
9+ namespace klib ::lpc1754::io::periph::detail::can {
10+ enum class mode {
11+ rd,
12+ td,
13+ };
14+
15+ template <typename Pin, mode Type, typename Periph>
16+ struct can {
17+ // pin of the peripheral
18+ using pin = Pin;
19+
20+ // type of the pin
21+ constexpr static mode type = Type;
22+
23+ // alternate function
24+ using periph = Periph;
25+ };
26+ }
27+
28+ namespace klib ::lpc1754::io::periph::lqfp_80 {
29+ template <
30+ typename Td = pins::package::lqfp_80::p38
31+ >
32+ struct can0 {
33+ // peripheral id (e.g can0, can1)
34+ constexpr static uint32_t id = 0 ;
35+
36+ // peripheral clock bit position
37+ constexpr static uint32_t clock_id = 13 ;
38+
39+ // interrupt id (including the arm vector table)
40+ constexpr static uint32_t interrupt_id = 41 ;
41+
42+ // port to the CAN hardware
43+ static inline CAN1_Type *const port = CAN1;
44+
45+ // amount of hardware buffers for transmitting data
46+ constexpr static uint32_t tx_buffers = 3 ;
47+
48+ // pins allowed per output pin. Used for determining if a pin is valid on compile time
49+ using td_pins = std::tuple<
50+ detail::can::can<pins::package::lqfp_80::p38, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_1>,
51+ detail::can::can<pins::package::lqfp_80::p44, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_3>
52+ >;
53+
54+ // pin configuration. Uses above mapping ()
55+ using rd = detail::can::can<pins::package::lqfp_80::p37, detail::can::mode::rd, core::lpc175x::io::detail::alternate::func_1>;
56+ using td = std::tuple_element<klib::io::peripheral::get_index<Td, td_pins>(), td_pins>::type;
57+ };
58+
59+ struct can1 {
60+ // peripheral id (e.g can0, can1)
61+ constexpr static uint32_t id = 1 ;
62+
63+ // peripheral clock bit position
64+ constexpr static uint32_t clock_id = 14 ;
65+
66+ // interrupt id (including the arm vector table)
67+ constexpr static uint32_t interrupt_id = 41 ;
68+
69+ // port to the CAN hardware
70+ static inline CAN1_Type *const port = CAN2;
71+
72+ // amount of hardware buffers for transmitting data
73+ constexpr static uint32_t tx_buffers = 3 ;
74+
75+ // P2.7 and P2.8 (80 pin package does not have the following so only 1 configuration for can1)
76+ using rd = detail::can::can<pins::package::lqfp_80::p51, detail::can::mode::rd, core::lpc175x::io::detail::alternate::func_1>;
77+ using td = detail::can::can<pins::package::lqfp_80::p50, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_1>;
78+ };
79+ }
80+
81+ namespace klib ::lpc1754::io {
82+ /* *
83+ * @brief lpc1754 can driver
84+ *
85+ * @tparam Can
86+ * @tparam CanTxBuffers amount of tx hardware buffers used. Can help
87+ * when a protocol needs a specific order of messages
88+ */
89+ template <typename Can, uint32_t CanTxBuffers = Can::tx_buffers>
90+ using can = core::lpc175x::io::can<Can, CanTxBuffers>;
91+ }
92+
93+ #endif
0 commit comments