ready to alpha

подготовка к альфа-тестированию
This commit is contained in:
khristolyubov committed 2024-08-19 22:44:04 +07:00
commit e36b851783
164 files changed
+27352

No files matched your search

+125
View File
@@ -0,0 +1,125 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#ifdef __cplusplus
extern "C" {
#endif
#include "mik32_hal_gpio.h"
#include "mik32_hal_timer32.h"
#include "wiring_constants.h"
extern bool spiNssPinIsBlocked;
// analog pins
#define PIN_A0 (14)
#define PIN_A1 (15)
#define PIN_A2 (16)
#define PIN_A3 (17)
// there are D18 and D19 between them
#define PIN_A4 (20)
#define PIN_A5 (21)
static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
// digital pins
// D0...D13, D18, D19
// User led and button
#define LED_BUILTIN (22)
#define BTN_BUILTIN (23)
// determines the address of the port by the board pin number to which this pin belongs on the MCU
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber);
// determines the pin address inside the port by the board pin number
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digPinNumber);
// оtotal number of pins available for initialization
uint16_t pinCommonQty(void);
// ADC
// determines the ADC channel number by the board pin number
uint32_t analogInputToChannelNumber(uint32_t PinNumber);
// PWM
bool digitalPinHasPWM(uint8_t p);
// determines which timer the pin belongs to
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to
HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber);
// SPI
#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
// config SEL_NSS1 to replace D10 to different controller pin,
// because pin 1.3 which is D10 by default is needed to spi
inline void blockSpiPin(void)
{
spiNssPinIsBlocked = true;
}
inline void unblockSpiPin(void)
{
spiNssPinIsBlocked = false;
}
// I2C
#define PIN_WIRE_SDA (18)
#define PIN_WIRE_SCL (19)
#define I2C_NUM (1) // i2c number 0 or 1
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
// available frequencies
#define WIRE_FREQ_100K 100000
#define WIRE_FREQ_400K 400000
#define WIRE_FREQ_1000K 1000000
// interrupts
#define EXTERNAL_NUM_INTERRUPTS 7
// determines the board pin number by interrupt number
uint32_t interruptToDigitalPin(uint8_t interruptNum);
// determines interrupt number by the board pin number
int8_t digitalPinToInterrupt(uint32_t digPinNumber);
// determines gpio interrupt line by interrupt number
uint32_t interruptToGpioIntLine(uint8_t interruptNum);
// determines interrupt number by the gpio interrupt line
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine);
// determines gpio interrupt mux by interrupt number
uint32_t interruptToGpioIntMux(uint8_t interruptNum);
#ifdef __cplusplus
}
#endif
#endif
+211
View File
@@ -0,0 +1,211 @@
/**
*******************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* All rights reserved.
*
* This software component is licensed by WCH under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#include "pins_arduino.h"
#include "mik32_hal_adc.h"
#ifdef __cplusplus
extern "C" {
#endif
void ErrorMsgHandler(const char * msg);
#ifdef __cplusplus
}
#endif
bool spiNssPinIsBlocked = false;
// list of pin numbers from both ports with pins inside the port
const HAL_PinsTypeDef digitalPinToGpioPinArray[] =
{
GPIO_PIN_5, // D0
GPIO_PIN_6, // D1
GPIO_PIN_10,// D2
GPIO_PIN_0, // D3
GPIO_PIN_8, // D4
GPIO_PIN_1, // D5
GPIO_PIN_2, // D6
GPIO_PIN_8, // D7
GPIO_PIN_9, // D8
GPIO_PIN_3, // D9
GPIO_PIN_3, // D10
GPIO_PIN_1, // D11
GPIO_PIN_0, // D12
GPIO_PIN_2, // D13
GPIO_PIN_5, // D14/A0
GPIO_PIN_7, // D15/A1
GPIO_PIN_4, // D16/A2
GPIO_PIN_7, // D17/A3
GPIO_PIN_12,// D18
GPIO_PIN_13,// D19
GPIO_PIN_9, // A4 (board pin 20)
GPIO_PIN_9, // A5 (board pin 21)
GPIO_PIN_7, // LED(pin 22)
GPIO_PIN_6 // BTN(pin 23)
};
// etermines the address of the port by the board pin number to which this pin belongs on the MCU
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
{
GPIO_TypeDef* gpioNum = 0;
// port 0 - board pins 0...6, 9, 16(A2), 17(A3), 20(A4), 21(A5)
if ((digPinNumber >= 0 && digPinNumber <= 6) || digPinNumber == 9 || digPinNumber == 16
|| digPinNumber == 17 || digPinNumber == 20 || digPinNumber == 21) // 12 pieces
gpioNum = GPIO_0;
// port 1 - board pins 7, 8, 10...13, 14(А0), 15(А1), 18,19
else if (digPinNumber == 7 || digPinNumber == 8 || (digPinNumber >= 10 && digPinNumber <= 15)
|| digPinNumber == 18 || digPinNumber == 19) // 10 pieces
gpioNum = GPIO_1;
// port 2 - led and button
else if (digPinNumber == LED_BUILTIN || digPinNumber == BTN_BUILTIN)
gpioNum = GPIO_2;
return gpioNum;
}
// determines the pin address inside the port by the board pin number
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digPinNumber)
{
if (digPinNumber < pinCommonQty())
{
HAL_PinsTypeDef mask;
// if spi is on default pin 1.3 is needed for spi, D10 is replaced to pin 1.4
if (spiNssPinIsBlocked && (digPinNumber == 10))
mask = GPIO_PIN_4;
else
mask = digitalPinToGpioPinArray[digPinNumber];
return mask;
}
else
return NC;
}
uint16_t pinCommonQty(void)
{
return (uint16_t)(sizeof(digitalPinToGpioPinArray)/sizeof(digitalPinToGpioPinArray[0]));
}
// ---------------------- АЦП ---------------------- //
// determines the ADC channel number by the board pin number
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
{
uint32_t adcChannel = 0;
switch (PinNumber)
{
case PIN_A0:
adcChannel = ADC_CHANNEL0;
break;
case PIN_A1:
adcChannel = ADC_CHANNEL1;
break;
case PIN_A2:
adcChannel = ADC_CHANNEL3;
break;
case PIN_A3:
adcChannel = ADC_CHANNEL4;
break;
case PIN_A4:
case PIN_A5:
adcChannel = ADC_CHANNEL5;
break;
default:
adcChannel = NC;
}
return adcChannel;
}
// ---------------------- PWM ---------------------- //
bool digitalPinHasPWM(uint8_t p)
{
bool ret = false;
// if spi is in use D10 cannot work as pwm
if (spiNssPinIsBlocked && (p == 10))
ret = false;
else if ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
ret = true;
return ret;
}
// function is used only if digitalPinHasPWM() is true
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber)
{
TIMER32_TypeDef* timerNum = NULL;
// timer 1
if (digPinNumber == 3 || digPinNumber == 5 || digPinNumber == 6 || digPinNumber == 9)
timerNum = TIMER32_1;
// timer 2
else if (digPinNumber == 10 || digPinNumber == 11)
timerNum = TIMER32_2;
return timerNum;
}
// function is used only if digitalPinHasPWM() is true
HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber)
{
HAL_TIMER32_CHANNEL_IndexTypeDef channel = 0;
if (digPinNumber == 3) channel = TIMER32_CHANNEL_0;
else if (digPinNumber == 5 || digPinNumber == 11) channel = TIMER32_CHANNEL_1;
else if (digPinNumber == 6) channel = TIMER32_CHANNEL_2;
else if (digPinNumber == 9 || digPinNumber == 10) channel = TIMER32_CHANNEL_3;
return channel;
}
// ---------------------- interrupts ---------------------- //
// interrupt table
// index = interrupt number. In each row {digitalPinNumber, IntLineValue, IntMuxValue}
const uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
{
{ 2, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT0
{ 3, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT0_0}, // INT1
{ 4, GPIO_LINE_4, GPIO_MUX_LINE_4_PORT0_8}, // INT2
{ 5, GPIO_LINE_1, GPIO_MUX_LINE_1_PORT0_1}, // INT3
{ 8, GPIO_LINE_5, GPIO_MUX_LINE_5_PORT1_9}, // INT4
{ 9, GPIO_LINE_3, GPIO_MUX_LINE_3_PORT0_3}, // INT5
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT6 (button)
};
uint32_t interruptToDigitalPin(uint8_t interruptNum)
{
return interruptInfo[interruptNum][0];
}
uint32_t interruptToGpioIntLine(uint8_t interruptNum)
{
return (uint32_t)interruptInfo[interruptNum][1];
}
uint32_t interruptToGpioIntMux(uint8_t interruptNum)
{
return (uint32_t)interruptInfo[interruptNum][2];
}
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine)
{
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
{
if (interruptInfo[i][1] == gpioIntLine)
return i;
}
return NOT_AN_INTERRUPT;
}
int8_t digitalPinToInterrupt(uint32_t digPinNumber)
{
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
{
if (interruptInfo[i][0] == digPinNumber)
return i;
}
return NOT_AN_INTERRUPT;
}