Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Jun 8, 2022
1 parent bc038af commit cfb69bd
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 181 deletions.
2 changes: 1 addition & 1 deletion ext/etlcpp/etl
Submodule etl updated 203 files
2 changes: 1 addition & 1 deletion ext/hathach/tinyusb
Submodule tinyusb updated 90 files
+20 −26 src/class/audio/audio_device.c
+4 −14 src/class/audio/audio_device.h
+56 −60 src/class/bth/bth_device.c
+5 −7 src/class/cdc/cdc_device.c
+1 −1 src/class/cdc/cdc_host.c
+1 −1 src/class/dfu/dfu_device.c
+1 −1 src/class/hid/hid.h
+6 −6 src/class/hid/hid_device.c
+32 −32 src/class/hid/hid_device.h
+1 −1 src/class/hid/hid_host.c
+0 −7 src/class/midi/midi_device.c
+30 −41 src/class/msc/msc_device.c
+0 −3 src/class/msc/msc_device.h
+1 −1 src/class/msc/msc_host.c
+32 −30 src/class/usbtmc/usbtmc_device.c
+6 −0 src/class/usbtmc/usbtmc_device.h
+0 −8 src/class/video/video.h
+43 −104 src/class/video/video_device.c
+46 −18 src/common/tusb_common.h
+1 −43 src/common/tusb_compiler.h
+11 −18 src/common/tusb_fifo.c
+21 −18 src/common/tusb_types.h
+2 −2 src/common/tusb_verify.h
+2 −2 src/device/dcd.h
+39 −97 src/device/dcd_attr.h
+23 −26 src/device/usbd.c
+2 −4 src/device/usbd.h
+23 −23 src/host/hcd_attr.h
+25 −34 src/host/usbh.c
+2 −4 src/osal/osal.h
+1 −3 src/osal/osal_freertos.h
+0 −170 src/osal/osal_rtx4.h
+0 −1,110 src/portable/bridgetek/ft9xx/dcd_ft9xx.c
+0 −1,267 src/portable/broadcom/synopsys/dcd_synopsys.c
+0 −1,476 src/portable/broadcom/synopsys/synopsys_common.h
+0 −50 src/portable/chipidea/ci_hs/ci_hs_imxrt.h
+0 −45 src/portable/chipidea/ci_hs/ci_hs_lpc18_43.h
+0 −144 src/portable/chipidea/ci_hs/ci_hs_type.h
+0 −637 src/portable/chipidea/ci_hs/dcd_ci_hs.c
+0 −93 src/portable/chipidea/ci_hs/hcd_ci_hs.c
+8 −17 src/portable/dialog/da146xx/dcd_da146xx.c
+4 −4 src/portable/ehci/ehci.c
+5 −4 src/portable/espressif/esp32sx/dcd_esp32sx.c
+0 −900 src/portable/mentor/musb/dcd_musb.c
+0 −876 src/portable/mentor/musb/hcd_musb.c
+0 −40 src/portable/mentor/musb/musb_msp432e.h
+0 −45 src/portable/mentor/musb/musb_tm4c.h
+0 −2,624 src/portable/mentor/musb/musb_type.h
+0 −741 src/portable/microchip/pic32mz/dcd_pic32mz.c
+0 −931 src/portable/microchip/pic32mz/usbhs_registers.h
+2 −2 src/portable/microchip/samd/dcd_samd.c
+1 −1 src/portable/microchip/samg/dcd_samg.c
+2 −2 src/portable/microchip/samx7x/dcd_samx7x.c
+1 −1 src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
+72 −103 src/portable/nordic/nrf5x/dcd_nrf5x.c
+1 −1 src/portable/nuvoton/nuc120/dcd_nuc120.c
+1 −1 src/portable/nuvoton/nuc121/dcd_nuc121.c
+2 −7 src/portable/nuvoton/nuc505/dcd_nuc505.c
+1 −1 src/portable/nxp/khci/dcd_khci.c
+0 −626 src/portable/nxp/khci/hcd_khci.c
+2 −3 src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+2 −4 src/portable/nxp/transdimension/dcd_transdimension.c
+0 −2 src/portable/nxp/transdimension/hcd_transdimension.c
+1 −1 src/portable/ohci/ohci.c
+1 −1 src/portable/ohci/ohci.h
+12 −28 src/portable/raspberrypi/rp2040/dcd_rp2040.c
+7 −24 src/portable/raspberrypi/rp2040/hcd_rp2040.c
+1 −1 src/portable/raspberrypi/rp2040/rp2040_usb.c
+3 −3 src/portable/renesas/usba/dcd_usba.c
+0 −870 src/portable/renesas/usba/hcd_usba.c
+937 −0 src/portable/silabs/efm32/dcd_efm32.c
+4 −6 src/portable/sony/cxd56/dcd_cxd56.c
+13 −24 src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
+0 −4 src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h
+7 −7 src/portable/st/synopsys/dcd_synopsys.c
+0 −1,211 src/portable/sunxi/dcd_sunxi_musb.c
+0 −643 src/portable/sunxi/musb_def.h
+0 −1,312 src/portable/synopsys/dwc2/dcd_dwc2.c
+0 −88 src/portable/synopsys/dwc2/dwc2_bcm.h
+0 −87 src/portable/synopsys/dwc2/dwc2_efm32.h
+0 −94 src/portable/synopsys/dwc2/dwc2_esp32.h
+0 −100 src/portable/synopsys/dwc2/dwc2_gd32.h
+0 −205 src/portable/synopsys/dwc2/dwc2_stm32.h
+0 −1,730 src/portable/synopsys/dwc2/dwc2_type.h
+0 −87 src/portable/synopsys/dwc2/dwc2_xmc.h
+0 −777 src/portable/synopsys/dwc2/hwcfg_list.md
+4 −3 src/portable/ti/msp430x5xx/dcd_msp430x5xx.c
+10 −10 src/portable/valentyusb/eptri/dcd_eptri.c
+4 −3 src/tusb.c
+15 −43 src/tusb_option.h
2 changes: 1 addition & 1 deletion ext/lvgl/lvgl
Submodule lvgl updated 266 files
2 changes: 1 addition & 1 deletion ext/modm-devices
Submodule modm-devices updated 40 files
+5 −13 .github/workflows/tests.yml
+8 −9 README.md
+0 −2 devices/avr/atmega-324-pb.xml
+0 −4 devices/avr/atmega-48_88_168_328-a_n_p_pa_pv_v.xml
+0 −4 devices/avr/atmega-48_88_168_328-pb.xml
+9 −9 devices/nrf/nrf52832.xml
+0 −538 devices/rp/rp2040.xml
+1 −1 devices/stm32/stm32f4-05_07_15_17.xml
+1 −1 devices/stm32/stm32f4-27_29_37_39.xml
+1 −1 devices/stm32/stm32f4-69_79.xml
+2 −2 devices/stm32/stm32g4-31_41.xml
+465 −92 devices/stm32/stm32g4-71_91_a1.xml
+119 −13 devices/stm32/stm32g4-73_83.xml
+125 −13 devices/stm32/stm32g4-74_84.xml
+0 −1,909 devices/stm32/stm32g4-91_a1.xml
+12 −26 devices/stm32/stm32h7-25_35.xml
+39 −39 devices/stm32/stm32h7-a3.xml
+39 −39 devices/stm32/stm32h7-b0.xml
+39 −39 devices/stm32/stm32h7-b3.xml
+1 −1 devices/stm32/stm32l4-12_22.xml
+0 −2,878 devices/stm32/stm32l5-52_62.xml
+8 −53 devices/stm32/stm32u5-75_85.xml
+73 −10 devices/stm32/stm32wl-54_55.xml
+73 −10 devices/stm32/stm32wl-e4_e5.xml
+1 −1 modm_devices/__init__.py
+3 −16 tools/generator/Makefile
+4 −4 tools/generator/dfg/nrf/nrf_device_tree.py
+0 −0 tools/generator/dfg/rp/__init__.py
+0 −381 tools/generator/dfg/rp/rp_device_tree.py
+0 −11 tools/generator/dfg/rp/rp_groups.py
+0 −37 tools/generator/dfg/rp/rp_identifier.py
+3 −37 tools/generator/dfg/stm32/stm.py
+1 −2 tools/generator/dfg/stm32/stm_device_tree.py
+1 −10 tools/generator/dfg/stm32/stm_groups.py
+10 −10 tools/generator/dfg/stm32/stm_peripherals.py
+23 −35 tools/generator/raw-data-extractor/extract-nrf.py
+0 −24 tools/generator/raw-data-extractor/extract-rp.py
+36 −234 tools/generator/raw-data-extractor/patches/stm32.patch
+0 −46 tools/generator/rp_generator.py
+0 −0 tools/scripts/sync_docs.py
2 changes: 1 addition & 1 deletion ext/st/stm32
Submodule stm32 updated 60 files
+3 −3 README.md
+11 −6 stm32f4xx/Include/stm32f401xc.h
+11 −6 stm32f4xx/Include/stm32f401xe.h
+11 −6 stm32f4xx/Include/stm32f405xx.h
+38 −39 stm32f4xx/Include/stm32f407xx.h
+11 −6 stm32f4xx/Include/stm32f410cx.h
+11 −6 stm32f4xx/Include/stm32f410rx.h
+11 −6 stm32f4xx/Include/stm32f410tx.h
+11 −6 stm32f4xx/Include/stm32f411xe.h
+11 −6 stm32f4xx/Include/stm32f412cx.h
+12 −7 stm32f4xx/Include/stm32f412rx.h
+12 −7 stm32f4xx/Include/stm32f412vx.h
+12 −7 stm32f4xx/Include/stm32f412zx.h
+12 −7 stm32f4xx/Include/stm32f413xx.h
+11 −6 stm32f4xx/Include/stm32f415xx.h
+38 −39 stm32f4xx/Include/stm32f417xx.h
+12 −7 stm32f4xx/Include/stm32f423xx.h
+40 −41 stm32f4xx/Include/stm32f427xx.h
+42 −43 stm32f4xx/Include/stm32f429xx.h
+40 −41 stm32f4xx/Include/stm32f437xx.h
+42 −43 stm32f4xx/Include/stm32f439xx.h
+13 −8 stm32f4xx/Include/stm32f446xx.h
+44 −45 stm32f4xx/Include/stm32f469xx.h
+44 −45 stm32f4xx/Include/stm32f479xx.h
+15 −9 stm32f4xx/Include/stm32f4xx.h
+23 −5 stm32f4xx/Include/system_stm32f4xx.h
+3,239 −699 stm32f4xx/Release_Notes.html
+3 −8 stm32h7xx/Include/stm32h723xx.h
+3 −8 stm32h7xx/Include/stm32h725xx.h
+3 −8 stm32h7xx/Include/stm32h730xx.h
+3 −8 stm32h7xx/Include/stm32h730xxq.h
+3 −8 stm32h7xx/Include/stm32h733xx.h
+3 −8 stm32h7xx/Include/stm32h735xx.h
+0 −3 stm32h7xx/Include/stm32h742xx.h
+1 −4 stm32h7xx/Include/stm32h743xx.h
+1 −4 stm32h7xx/Include/stm32h745xg.h
+0 −3 stm32h7xx/Include/stm32h745xx.h
+1 −4 stm32h7xx/Include/stm32h747xg.h
+0 −3 stm32h7xx/Include/stm32h747xx.h
+1 −4 stm32h7xx/Include/stm32h750xx.h
+1 −4 stm32h7xx/Include/stm32h753xx.h
+0 −3 stm32h7xx/Include/stm32h755xx.h
+0 −3 stm32h7xx/Include/stm32h757xx.h
+3 −8 stm32h7xx/Include/stm32h7a3xx.h
+3 −8 stm32h7xx/Include/stm32h7a3xxq.h
+3 −8 stm32h7xx/Include/stm32h7b0xx.h
+3 −8 stm32h7xx/Include/stm32h7b0xxq.h
+3 −8 stm32h7xx/Include/stm32h7b3xx.h
+3 −8 stm32h7xx/Include/stm32h7b3xxq.h
+2 −2 stm32h7xx/Include/stm32h7xx.h
+56 −91 stm32h7xx/Release_Notes.html
+1 −8 stm32u5xx/Include/partition_stm32u5xx.h
+603 −1,026 stm32u5xx/Include/stm32u575xx.h
+604 −1,027 stm32u5xx/Include/stm32u585xx.h
+0 −25,458 stm32u5xx/Include/stm32u595xx.h
+0 −29,316 stm32u5xx/Include/stm32u599xx.h
+0 −26,330 stm32u5xx/Include/stm32u5a5xx.h
+0 −30,188 stm32u5xx/Include/stm32u5a9xx.h
+5 −19 stm32u5xx/Include/stm32u5xx.h
+2 −32 stm32u5xx/Release_Notes.html
160 changes: 73 additions & 87 deletions src/modm/math/filter/moving_average.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,107 +17,93 @@
*/
// ----------------------------------------------------------------------------
#pragma once

#include <cstddef>
#include <cstdint>

#include <concepts>
#include <span>
#include <algorithm>
#include <modm/math/utils/integer_traits.hpp>

namespace modm
{
namespace filter{
/**
* \brief Moving average filter
*
* Calculates the average of N newest values, i.a. the sum of the last N
* values have been passed to update(...), divided by N. If less than N
* values have been passed to the filter, the division factor is still N,
* so missing values are assumed to be zero.
*
* For integer types this implementation stores the current sum of all values in the buffer
* and updates this value with every call of update() by subtracting
* the overwritten buffer index and adding the new one.
*
* Due to numerical instabillity for floating value types, inside the update function
* the sum has to be recalculated making it less efficient.
*
* The internal sum is always up to date and the getValue()
* method consists of only one division.
*
* \warning Input range is limited by the following equation
* \code N * input::maxValue < T::maxValue \endcode
* The sum off the last N input values must not be greater than
* the maximum value of T, otherwise an overflow will occur.
*
* \tparam T Input type
* \tparam N Number of samples (maximum is 65356 or 2**16)
*
* \ingroup modm_math_filter
*/
template<typename T, std::size_t N>
class MovingAverage
{
public:
MovingAverage(const T& initialValue = 0);
#include <numeric>

/// Reset whole buffer to 'input'
/// Next call of getValue() returns 'input'
void reset(const T& input);

/// Append new value
void
update(const T& input);

/// Get filtered value
const T
getValue() const;

private:
least_uint<N> index{0};
T buffer[N];
T sum;
};
}
}
#include <modm/math/utils/integer_traits.hpp>

// ----------------------------------------------------------------------------
template<typename T, std::size_t N>
modm::filter::MovingAverage<T, N>::MovingAverage(const T& initialValue)
namespace modm::filter
{
reset(initialValue);
}

// ----------------------------------------------------------------------------
/**
* \brief Moving average filter
*
* Calculates the average of N newest values, i.a. the sum of the last N
* values have been passed to update(...), divided by N. If less than N
* values have been passed to the filter, the division factor is still N,
* so missing values are assumed to be zero.
*
* For integer types this implementation stores the current sum of all values in the buffer
* and updates this value with every call of update() by subtracting
* the overwritten buffer index and adding the new one.
*
* Due to numerical instabillity for floating value types, inside the update function
* the sum has to be recalculated making it less efficient.
*
* The internal sum is always up to date and the getValue()
* method consists of only one division.
*
* \warning Input range is limited by the following equation
* \code N * input::maxValue < T::maxValue \endcode
* The sum off the last N input values must not be greater than
* the maximum value of T, otherwise an overflow will occur.
*
* \tparam T Input type
* \tparam N Number of samples
*
* \ingroup modm_math_filter
*/
template<typename T, std::size_t N>
void
modm::filter::MovingAverage<T, N>::reset(const T& input)
class MovingAverage
{
std::fill(std::begin(buffer), std::end(buffer), input);
sum = N * input;
}
public:
constexpr MovingAverage(T initialValue = 0)
{
reset(initialValue);
}

// ----------------------------------------------------------------------------
template<typename T, std::size_t N>
void
modm::filter::MovingAverage<T, N>::update(const T& input)
{
sum -= buffer[index];
sum += input;
/// Reset whole buffer to 'input'
/// Next call of getValue() returns 'input'
constexpr void reset(T input)
{
std::fill(std::begin(buffer), std::end(buffer), input);
sum = N * input;
}

buffer[index] = input;
/// Append new value
constexpr void
update(T input)
{
if constexpr(std::floating_point<T>) {
buffer[index] = input;
sum = std::accumulate(std::begin(buffer), std::end(buffer), 0);
} else {
sum -= buffer[index];
sum += input;
buffer[index] = input;
}

if (++index >= N)
index = 0;
}
if (++index == N)
index = 0;
}

// -----------------------------------------------------------------------------
template<typename T, std::size_t N>
const T
modm::filter::MovingAverage<T, N>::getValue() const
{
return (sum / static_cast<T>(N));
}
/// Get filtered value
T
constexpr getValue() const
{
return (sum / static_cast<T>(N));
}

private:
least_uint<N> index{0};
T buffer[N];
T sum;
};

#include "moving_average_float_impl.hpp"
} // namespace modm::filter
85 changes: 0 additions & 85 deletions src/modm/math/filter/moving_average_float_impl.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/modm/math/filter/moving_average_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ MovingAverageTest::testFloatReset()
}

filter.reset(42.23);
TEST_ASSERT_EQUALS(filter.getValue(), 42.23);
TEST_ASSERT_EQUALS_DELTA(filter.getValue(), 42.23, double(1e-4));
}

0 comments on commit cfb69bd

Please sign in to comment.