libyggdrasil  v1.0.0
i2c.hpp
Go to the documentation of this file.
1  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * _____.___. .___ .__.__ *
3  * \__ | | ____ ____ __| _/___________ _____|__| | *
4  * / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5  * \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6  * / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7  * \/ /_____//_____/ \/ \/ \/ *
8  * - Asgard - *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * This software can be used by students and other personal of the *
11  * Bern University of Applied Sciences under the terms of the MIT *
12  * license. *
13  * For other persons this software is under the terms of the GNU *
14  * General Public License version 2. *
15  * *
16  * Copyright © 2021, Bern University of Applied Sciences. *
17  * All rights reserved. *
18  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 #pragma once
27 
29 
30 #include <string>
31 #include <string_view>
32 #include <array>
33 
34 namespace bsp::asg_coproc::drv {
35 
42  template<auto Context>
43  struct I2C {
44 
50  static bool init() {
51  return true;
52  }
53 
59  static bool deinit() {
60  return true;
61  }
62 
70  template<size_t N>
71  ALWAYS_INLINE static void read(u8 address, std::array<u8, N> &data) {
72  HAL_I2C_Master_Receive(Context, address, data.data(), data.size(), HAL_MAX_DELAY);
73  }
74 
82  template<size_t N>
83  ALWAYS_INLINE static void write(u8 address, const std::array<u8, N> &data) {
84  HAL_I2C_Master_Transmit(Context, address, const_cast<u8*>(data.data()), data.size(), HAL_MAX_DELAY);
85  }
86  };
87 
88 }
bsp::asg_coproc::drv::I2C::read
static ALWAYS_INLINE void read(u8 address, std::array< u8, N > &data)
I2C receive.
Definition: i2c.hpp:71
u8
uint8_t u8
Unsigned integer definitions.
Definition: types.h:36
bsp::asg_coproc::drv
Definition: adc.hpp:32
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: attributes.h:34
i2c.hpp
Frontend for the I2C abstraction.
bsp::asg_coproc::drv::I2C::init
static bool init()
Init function.
Definition: i2c.hpp:50
bsp::asg_coproc::drv::I2C
I2C implementation for Asgard.
Definition: i2c.hpp:43
bsp::asg_coproc::drv::I2C::write
static ALWAYS_INLINE void write(u8 address, const std::array< u8, N > &data)
I2C write.
Definition: i2c.hpp:83
bsp::asg_coproc::drv::I2C::deinit
static bool deinit()
Deinit function.
Definition: i2c.hpp:59