Skip to content

Commit 6632a19

Browse files
committed
added :driver:encoder_input
1 parent b808639 commit 6632a19

File tree

3 files changed

+115
-10
lines changed

3 files changed

+115
-10
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -607,72 +607,73 @@ you specific needs.
607607
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
608608
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
609609
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
610+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">ENCODER-INPUT</a></td>
610611
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">ENCODER-INPUT-BITBANG</a></td>
611-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">ENCODER-OUTPUT-BITBANG</a></td>
612612
</tr><tr>
613+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">ENCODER-OUTPUT-BITBANG</a></td>
613614
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
614615
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6X06</a></td>
615616
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">GPIO-SAMPLER</a></td>
616617
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
617618
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
618-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
619619
</tr><tr>
620+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
620621
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
621622
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
622623
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
623624
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
624625
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
625-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
626626
</tr><tr>
627+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
627628
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
628629
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
629630
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
630631
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
631632
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
632-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
633633
</tr><tr>
634+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
634635
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
635636
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503X</a></td>
636637
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
637638
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
638639
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
639-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
640640
</tr><tr>
641+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
641642
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
642643
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23X17</a></td>
643644
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
644645
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
645646
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
646-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
647647
</tr><tr>
648+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
648649
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
649650
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
650651
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
651652
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
652653
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
653-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
654654
</tr><tr>
655+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
655656
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
656657
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
657658
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
658659
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
659660
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
660-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
661661
</tr><tr>
662+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
662663
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
663664
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
664665
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
665666
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
666667
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
667-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
668668
</tr><tr>
669+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
669670
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594X</a></td>
670671
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
671672
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12X</a></td>
672673
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
673674
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
674-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
675675
</tr><tr>
676+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
676677
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
677678
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
678679
</tr>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2021, Thomas Sommer
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#pragma once
12+
13+
#include <modm/platform.hpp>
14+
15+
namespace modm
16+
{
17+
/**
18+
* @brief Gray code decoder using STM32 Timer mode
19+
*
20+
* @tparam Timer STM32 General purpose timer
21+
* @tparam SignalA First modm::platform::Gpio pin that connects to Timer::Ch1
22+
* @tparam SignalB Second modm::platform::Gpio pin that connects to Timer::Ch2
23+
* @tparam PRESCALER How many encoder pulses to count as one
24+
* @tparam DeltaType Fast encoders may require int16_t
25+
*/
26+
template<class Timer, typename SignalA, typename SignalB, uint16_t PRESCALER = 4,
27+
std::signed_integral DeltaType = int16_t>
28+
class EncoderInput
29+
{
30+
public:
31+
void
32+
initialize(
33+
const uint8_t filter = 4,
34+
const modm::platform::Gpio::InputType inputType = modm::platform::Gpio::InputType::PullUp
35+
) {
36+
SignalA::setInput(inputType);
37+
SignalB::setInput(inputType);
38+
39+
Timer::template connect<typename SignalA::Ch1, typename SignalB::Ch2>();
40+
41+
Timer::enable();
42+
43+
Timer::setMode(Timer::Mode::UpCounter, Timer::SlaveMode::Encoder3);
44+
Timer::setPrescaler(PRESCALER);
45+
46+
if(filter) {
47+
Timer::configureInputChannel(1, filter);
48+
Timer::configureInputChannel(2, filter);
49+
}
50+
51+
Timer::applyAndReset();
52+
Timer::start();
53+
last = Timer::getValue();
54+
}
55+
56+
uint16_t
57+
getValue()
58+
{
59+
return Timer::getValue();
60+
}
61+
62+
DeltaType
63+
getDelta()
64+
{
65+
uint16_t current = Timer::getValue();
66+
const DeltaType delta = current - last;
67+
last = current;
68+
69+
return delta;
70+
}
71+
72+
73+
private:
74+
uint16_t last = 0;
75+
};
76+
} // namespace modm
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2021, Thomas Sommer
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
def init(module):
14+
module.name = ":driver:encoder_input"
15+
module.description = """
16+
# Quadrature Encoder Input using STM32 general purpose Timer
17+
18+
This driver decodes an AB (incremental) encoder signal.
19+
"""
20+
21+
def prepare(module, options):
22+
module.depends(":architecture:atomic")
23+
return options[":target"].identifier.platform =="stm32"
24+
25+
26+
def build(env):
27+
env.outbasepath = "modm/src/modm/driver/encoder"
28+
env.copy("encoder_input.hpp")

0 commit comments

Comments
 (0)