-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (72 loc) · 2.41 KB
/
main.cpp
File metadata and controls
84 lines (72 loc) · 2.41 KB
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
/*
* Copyright (c) 2018, Sascha Schade
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <modm/architecture/interface/i2c_device.hpp>
#include <modm/architecture/interface/i2c_multiplexer.hpp>
#include <modm/driver/gpio/pca9548a.hpp>
using MyI2cMaster = modm::platform::I2cMaster1;
using Mpx = modm::Pca9548a<MyI2cMaster>;
using I2cMultiplexer = modm::I2cMultiplexer<MyI2cMaster, Mpx>;
namespace multiplexer
{
I2cMultiplexer i2cMultiplexer;
// Instances for each channel
using Ch0 = I2cMultiplexer::Ch0< i2cMultiplexer >;
using Ch1 = I2cMultiplexer::Ch1< i2cMultiplexer >;
using Ch2 = I2cMultiplexer::Ch2< i2cMultiplexer >;
using Ch3 = I2cMultiplexer::Ch3< i2cMultiplexer >;
using Ch4 = I2cMultiplexer::Ch4< i2cMultiplexer >;
using Ch5 = I2cMultiplexer::Ch5< i2cMultiplexer >;
using Ch6 = I2cMultiplexer::Ch6< i2cMultiplexer >;
using Ch7 = I2cMultiplexer::Ch7< i2cMultiplexer >;
}
modm::I2cDevice<multiplexer::Ch1> dev0(0x29);
modm::I2cDevice<multiplexer::Ch2> dev1(0x29);
modm::I2cDevice<multiplexer::Ch3> dev2(0x29);
modm::I2cDevice<multiplexer::Ch7> dev3(0x29);
modm::Fiber fiber_ping([]
{
MODM_LOG_DEBUG << MODM_FILE_INFO;
MODM_LOG_DEBUG << "Ping the Devices" << modm::endl;
// ping the devices repeatedly
while(true)
{
MODM_LOG_DEBUG.printf("[dev ] ping0\n");
MODM_LOG_DEBUG.printf("[dev ] ping0 res: %d\n", dev0.ping());
MODM_LOG_DEBUG.printf("[dev ] ping1\n");
MODM_LOG_DEBUG.printf("[dev ] ping1 res: %d\n", dev1.ping());
MODM_LOG_DEBUG.printf("[dev ] ping2\n");
MODM_LOG_DEBUG.printf("[dev ] ping2 res: %d\n", dev2.ping());
MODM_LOG_DEBUG.printf("[dev ] ping3\n");
MODM_LOG_DEBUG.printf("[dev ] ping3 res: %d\n", dev3.ping());
// Do again in 1s
modm::this_fiber::sleep_for(1s);
}
});
modm::Fiber fiber_blink([]
{
uint32_t counter{};
while (true)
{
Board::Leds::toggle();
MODM_LOG_INFO << "Loop counter: " << (counter++) << modm::endl;
modm::this_fiber::sleep_for(1s);
}
});
int
main()
{
Board::initialize();
modm::platform::I2cMaster1::connect<modm::platform::GpioB7::Sda, modm::platform::GpioB6::Scl>();
modm::platform::I2cMaster1::initialize<Board::SystemClock, 100_kHz>();
modm::fiber::Scheduler::run();
return 0;
}