v2.0.0 Add support for ESP32S2 and update ESP-IDF to 4.4 (#4996)

This is very much still work in progress and much more will change before the final 2.0.0

Some APIs have changed. New libraries have been added. LittleFS included.

Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Mike Dunston <m_dunston@comcast.net>
Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com>
Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com>
Co-authored-by: tobozo <tobozo@users.noreply.github.com>
Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com>
Co-authored-by: lorol <lorolouis@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net>
Co-authored-by: Sweety <switi.mhaiske@espressif.com>
Co-authored-by: Loick MAHIEUX <loick111@gmail.com>
Co-authored-by: Larry Bernstone <lbernstone@gmail.com>
Co-authored-by: Valerii Koval <valeros@users.noreply.github.com>
Co-authored-by: 快乐的我531 <2302004040@qq.com>
Co-authored-by: chegewara <imperiaonline4@gmail.com>
Co-authored-by: Clemens Kirchgatterer <clemens@1541.org>
Co-authored-by: Aron Rubin <aronrubin@gmail.com>
Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
This commit is contained in:
Me No Dev
2021-04-05 14:23:58 +03:00
committed by GitHub
parent 46d5afb17f
commit 5502879a5b
5209 changed files with 826360 additions and 322816 deletions

View File

@ -0,0 +1,182 @@
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _dspm_mult_H_
#define _dspm_mult_H_
#include "dsp_err.h"
#include "dspm_mult_platform.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**@{*/
/**
* @brief Matrix multiplication
*
* Matrix multiplication for two floating point matrices: C[m][k] = A[m][n] * B[n][k]
* The extension (_ansi) use ANSI C and could be compiled and run on any platform.
* The extension (_ae32) is optimized for ESP32 chip.
*
* @param[in] A input matrix A[m][n]
* @param[in] B input matrix B[n][k]
* @param C result matrix C[m][k]
* @param[in] m matrix dimension
* @param[in] n matrix dimension
* @param[in] k matrix dimension
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_f32_ansi(const float *A, const float *B, float *C, int m, int n, int k);
esp_err_t dspm_mult_f32_ae32(const float *A, const float *B, float *C, int m, int n, int k);
/**@}*/
/**
* @brief Matrix multiplication A[3x3]xB[3x1]
*
* Matrix multiplication for two floating point matrices 3x3 and 3x1: C[1][3] = A[3][3] * B[3][1]
* The implementation is optimized for ESP32 chip.
*
* @param[in] A input matrix A[3][3]
* @param[in] B input matrix/vector B[3][1]
* @param C result matrix/vector C[3][3]
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_3x3x1_f32_ae32(const float *A, const float *B, float *C);
/**
* @brief Matrix multiplication A[3x3]xB[3x3]
*
* Matrix multiplication for two square 3x3 floating point matrices: C[3][3] = A[3][3] * B[3][3]
* The implementation is optimized for ESP32 chip.
*
* @param[in] A input matrix A[3][3]
* @param[in] B input matrix B[3][3]
* @param C result matrix C[3][3]
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_3x3x3_f32_ae32(const float *A, const float *B, float *C);
/**
* @brief Matrix multiplication A[4x4]xB[4x1]
*
* Matrix multiplication for two floating point matrices 4x4 and 4x1: C[1][4] = A[4][4] * B[4][1]
* The implementation is optimized for ESP32 chip.
*
* @param[in] A input matrix A[4][4]
* @param[in] B input matrix/vector B[4][1]
* @param C result matrix/vector C[4][4]
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_4x4x1_f32_ae32(const float *A, const float *B, float *C);
/**
* @brief Matrix multiplication A[4x4]xB[4x4]
*
* Matrix multiplication for two square 3x3 floating point matrices: C[4][4] = A[4][4] * B[4][4]
* The implementation is optimized for ESP32 chip.
*
* @param[in] A input matrix A[4][4]
* @param[in] B input matrix B[4][4]
* @param C result matrix C[4][4]
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_4x4x4_f32_ae32(const float *A, const float *B, float *C);
/**@{*/
/**
* @brief Matrix multiplication 16 bit signeg int
*
* Matrix multiplication for two signed 16 bit fixed point matrices: C[m][k] = (A[m][n] * B[n][k]) >> (15- shift)
* The extension (_ansi) use ANSI C and could be compiled and run on any platform.
* The extension (_ae32) is optimized for ESP32 chip.
*
* @param[in] A input matrix A[m][n]
* @param[in] B input matrix B[n][k]
* @param C result matrix C[m][k]
* @param[in] m matrix dimension
* @param[in] n matrix dimension
* @param[in] k matrix dimension
* @param[in] shift every result will be shifted and stored as 16 bit signed value.
* @return
* - ESP_OK on success
* - One of the error codes from DSP library
*/
esp_err_t dspm_mult_s16_ansi(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift);
esp_err_t dspm_mult_s16_ae32(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift);
/**@}*/
#ifdef __cplusplus
}
#endif
#if CONFIG_DSP_OPTIMIZED
#if (dspm_mult_s16_ae32_enabled == 1)
#define dspm_mult_s16 dspm_mult_s16_ae32
#else
#define dspm_mult_s16 dspm_mult_s16_ansi
#endif
#if (dspm_mult_f32_ae32_enabled == 1)
#define dspm_mult_f32 dspm_mult_f32_ae32
#else
#define dspm_mult_f32 dspm_mult_f32_ansi
#endif
#if (dspm_mult_3x3x1_f32_ae32_enabled == 1)
#define dspm_mult_3x3x1_f32 dspm_mult_3x3x1_f32_ae32
#else
#define dspm_mult_3x3x1_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 3, 3, 1)
#endif
#if (dspm_mult_3x3x3_f32_ae32_enabled == 1)
#define dspm_mult_3x3x3_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 3, 3, 3)
#else
#define dsps_sub_f32 dsps_sub_f32_ansi
#endif
#if (dspm_mult_4x4x1_f32_ae32_enabled == 1)
#define dspm_mult_4x4x1_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 4, 4, 1)
#else
#define dsps_sub_f32 dsps_sub_f32_ansi
#endif
#if (dspm_mult_4x4x4_f32_ae32_enabled == 1)
#define dspm_mult_4x4x4_f32 dspm_mult_4x4x4_f32_ae32
#else
#define dspm_mult_4x4x4_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 4, 4, 4)
#endif
#else
#define dspm_mult_s16 dspm_mult_s16_ansi
#define dspm_mult_f32 dspm_mult_f32_ansi
#define dspm_mult_3x3x1_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 3, 3, 1)
#define dsps_sub_f32 dsps_sub_f32_ansi
#define dsps_sub_f32 dsps_sub_f32_ansi
#define dspm_mult_4x4x4_f32(A,B,C) dspm_mult_f32_ansi(A,B,C, 4, 4, 4)
#endif // CONFIG_DSP_OPTIMIZED
#endif // _dspm_mult_H_

View File

@ -0,0 +1,26 @@
#ifndef _dspm_mult_platform_H_
#define _dspm_mult_platform_H_
#include <xtensa/config/core-isa.h>
#include <xtensa/config/core-matmap.h>
#if ((XCHAL_HAVE_FP == 1) && (XCHAL_HAVE_LOOPS == 1))
#define dspm_mult_f32_ae32_enabled 1
#define dspm_mult_3x3x1_f32_ae32_enabled 1
#define dspm_mult_3x3x3_f32_ae32_enabled 1
#define dspm_mult_4x4x1_f32_ae32_enabled 1
#define dspm_mult_4x4x4_f32_ae32_enabled 1
#endif
#if ((XCHAL_HAVE_LOOPS == 1) && (XCHAL_HAVE_MAC16 == 1))
#define dspm_mult_s16_ae32_enabled 1
#endif
#endif // _dspm_mult_platform_H_

View File

@ -0,0 +1,504 @@
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _dspm_mat_h_
#define _dspm_mat_h_
#include <iostream>
/**
* @brief DSP matrix namespace
*
* DSP library matrix namespace.
*/
namespace dspm {
/**
* @brief Matrix
*
* The Mat class provides basic matrix operations on single-precision floating point values.
*/
class Mat {
public:
/**
* Constructor allocate internal buffer.
* @param[in] rows: amount of matrix rows
* @param[in] cols: amount of matrix columns
*/
Mat(int rows, int cols);
/**
* Constructor use external buffer.
* @param[in] data: external buffer with row-major matrix data
* @param[in] rows: amount of matrix rows
* @param[in] cols: amount of matrix columns
*/
Mat(float *data, int rows, int cols);
/**
* Allocate matrix with undefined size.
*/
Mat();
virtual ~Mat();
/**
* Make copy of matrix.
* @param[in] src: source matrix
*/
Mat(const Mat &src);
/**
* Copy operator
*
* @param[in] src: source matrix
*
* @return
* - matrix copy
*/
Mat &operator=(const Mat &src);
bool ext_buff; /*!< Flag indicates that matrix use external buffer*/
/**
* Access to the matrix elements.
* @param[in] row: row position
* @param[in] col: column position
*
* @return
* - element of matrix M[row][col]
*/
inline float &operator()(int row, int col)
{
return data[row * this->cols + col];
}
/**
* Access to the matrix elements.
* @param[in] row: row position
* @param[in] col: column position
*
* @return
* - element of matrix M[row][col]
*/
inline const float &operator()(int row, int col) const
{
return data[row * this->cols + col];
}
/**
* += operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: source matrix
*
* @return
* - result matrix: result += A
*/
Mat &operator+=(const Mat &A);
/**
* += operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] C: constant
*
* @return
* - result matrix: result += C
*/
Mat &operator+=(float C);
/**
* -= operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: source matrix
*
* @return
* - result matrix: result -= A
*/
Mat &operator-=(const Mat &A);
/**
* -= operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] C: constant
*
* @return
* - result matrix: result -= C
*/
Mat &operator-=(float C);
/**
* *= operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: source matrix
*
* @return
* - result matrix: result -= A
*/
Mat &operator*=(const Mat &A);
/**
* += with constant operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] C: constant value
*
* @return
* - result matrix: result *= C
*/
Mat &operator*=(float C);
/**
* /= with constant operator
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] C: constant value
*
* @return
* - result matrix: result /= C
*/
Mat &operator/=(float C);
/**
* /= operator
*
* @param[in] B: source matrix
*
* @return
* - result matrix: result[i,j] = result[i,j]/B[i,j]
*/
Mat &operator/=(const Mat &B);
/**
* ^= xor with constant operator
* The operator use DSP optimized implementation of multiplication.
* @param[in] C: constant value
*
* @return
* - result matrix: result ^= C
*/
Mat operator^(int C);
/**
* Swap two rows between each other.
* @param[in] row1: position of first row
* @param[in] row2: position of second row
*/
void swapRows(int row1, int row2);
/**
* Matrix transpose.
* Change rows and columns between each other.
*
* @return
* - transposed matrix
*/
Mat t();
/**
* Create identity matrix.
* Create a square matrix and fill diagonal with 1.
*
* @param[in] size: matrix size
*
* @return
* - matrix [N]x[N] with 1 in diagonal
*/
static Mat eye(int size);
/**
* Create matrix with all elements 1.
* Create a square matrix and fill all elements with 1.
*
* @param[in] size: matrix size
*
* @return
* - matrix [N]x[N] with 1 in all elements
*/
static Mat ones(int size);
/**
* Return part of matrix from defined position (startRow, startCol) as a matrix[blockRows x blockCols].
*
* @param[in] startRow: start row position
* @param[in] startCol: start column position
* @param[in] blockRows: amount of rows in result matrix
* @param[in] blockCols: amount of columns in the result matrix
*
* @return
* - matrix [blockRows]x[blockCols]
*/
Mat block(int startRow, int startCol, int blockRows, int blockCols);
/**
* Normalizes the vector, i.e. divides it by its own norm.
* If it's matrix, calculate matrix norm
*
*/
void normalize(void);
/**
* Return norm of the vector.
* If it's matrix, calculate matrix norm
*
* @return
* - matrix norm
*/
float norm(void);
/**
* The method fill 0 to the matrix structure.
*
*/
void clear(void);
/**
* @brief Solve the matrix
*
* Solve matrix. Find roots for the matrix A*x = b
*
* @param[in] A: matrix [N]x[N] with input coefficients
* @param[in] b: vector [N]x[1] with result values
*
* @return
* - matrix [N]x[1] with roots
*/
static Mat solve(Mat A, Mat b);
/**
* @brief Band solve the matrix
*
* Solve band matrix. Find roots for the matrix A*x = b with bandwidth k.
*
* @param[in] A: matrix [N]x[N] with input coefficients
* @param[in] b: vector [N]x[1] with result values
* @param[in] k: upper bandwidth value
*
* @return
* - matrix [N]x[1] with roots
*/
static Mat bandSolve(Mat A, Mat b, int k);
/**
* @brief Solve the matrix
*
* Different way to solve the matrix. Find roots for the matrix A*x = y
*
* @param[in] A: matrix [N]x[N] with input coefficients
* @param[in] y: vector [N]x[1] with result values
*
* @return
* - matrix [N]x[1] with roots
*/
static Mat roots(Mat A, Mat y);
/**
* @brief Dotproduct of two vectors
*
* The method returns dotproduct of two vectors
*
* @param[in] A: Input vector A Nx1
* @param[in] B: Input vector B Nx1
*
* @return
* - dotproduct value
*/
static float dotProduct(Mat A, Mat B);
/**
* @brief Augmented matrices
*
* Augmented matrices
*
* @param[in] A: Input vector A MxN
* @param[in] B: Input vector B MxK
*
* @return
* - Augmented matrix Mx(N+K)
*/
static Mat augment(Mat A, Mat B);
/**
* @brief Gaussian Elimination
*
* Gaussian Elimination of matrix
*
* @return
* - result matrix
*/
Mat gaussianEliminate();
/**
* Row reduction for Gaussian elimination
*
* @return
* - result matrix
*/
Mat rowReduceFromGaussian();
/**
* Find the inverse matrix
*
* @return
* - inverse matrix
*/
Mat inverse();
/**
* Find pseudo inverse matrix
*
* @return
* - inverse matrix
*/
Mat pinv();
int rows; /*!< Amount of rows*/
int cols; /*!< Amount of columns*/
float *data; /*!< Buffer with matrix data*/
int length; /*!< Total amount of data in data array*/
static float abs_tol; /*!< Max acceptable absolute tolerance*/
private:
Mat cofactor(int row, int col, int n);
float det(int n);
Mat adjoint();
void allocate(); // Allocate buffer
Mat expHelper(const Mat &m, int num);
};
/**
* Print matrix to the standard iostream.
* @param[in] os: output stream
* @param[in] m: matrix to print
*
* @return
* - output stream
*/
std::ostream &operator<<(std::ostream &os, const Mat &m);
/**
* Fill the matrix from iostream.
* @param[in] is: input stream
* @param[in] m: matrix to fill
*
* @return
* - input stream
*/
std::istream &operator>>(std::istream &is, Mat &m);
/**
* + operator, sum of two matrices
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] B: Input matrix B
*
* @return
* - result matrix A+B
*/
Mat operator+(const Mat &A, const Mat &B);
/**
* + operator, sum of matrix with constant
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] C: Input constant
*
* @return
* - result matrix A+C
*/
Mat operator+(const Mat &A, float C);
/**
* - operator, subtraction of two matrices
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] B: Input matrix B
*
* @return
* - result matrix A-B
*/
Mat operator-(const Mat &A, const Mat &B);
/**
* - operator, sum of matrix with constant
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] C: Input constant
*
* @return
* - result matrix A+C
*/
Mat operator-(const Mat &A, float C);
/**
* * operator, multiplication of two matrices.
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] B: Input matrix B
*
* @return
* - result matrix A*B
*/
Mat operator*(const Mat &A, const Mat &B);
/**
* * operator, multiplication of matrix with constant
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] C: floating point value
*
* @return
* - result matrix A*B
*/
Mat operator*(const Mat &A, float C);
/**
* * operator, multiplication of matrix with constant
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] C: floating point value
* @param[in] A: Input matrix A
*
* @return
* - result matrix A*B
*/
Mat operator*(float C, const Mat &A);
/**
* / operator, divide of matrix by constant
* The operator use DSP optimized implementation of multiplication.
*
* @param[in] A: Input matrix A
* @param[in] C: floating point value
*
* @return
* - result matrix A*B
*/
Mat operator/(const Mat &A, float C);
/**
* / operator, divide matrix A by matrix B
*
* @param[in] A: Input matrix A
* @param[in] B: Input matrix B
*
* @return
* - result matrix C, where C[i,j] = A[i,j]/B[i,j]
*/
Mat operator/(const Mat &A, const Mat &B);
/**
* == operator, compare two matrices
*
* @param[in] A: Input matrix A
* @param[in] B: Input matrix B
*
* @return
* - true if matrices are the same
* - false if matrices are different
*/
bool operator==(const Mat &A, const Mat &B);
}
#endif //_dspm_mat_h_