// YC3121_PT26\Librarier\core
// board_config.h .........................
/*
File Name : board_config.h
Author : Yichip
Version : V1.0
Date : 2020/07/17
Description : board I/O config file.
*/
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__
#include "yc3121.h"
#include "yc_gpio.h"
#include "yc_spi.h"
#include "yc_adc.h"
#include "yc_chrg.h"
//ADC绠¤剼?嶇?
#define ADC_IO_PORT GPIOC
#define ADC1_IO_PIN GPIO_Pin_6
#define ADC2_IO_PIN GPIO_Pin_7
#define ADC3_IO_PIN GPIO_Pin_8
#define ADC4_IO_PIN GPIO_Pin_9
#define ADC_GAP_PIN ADC1_IO_PIN
#define ADC_BM_PIN ADC2_IO_PIN
#define ADC_TM_PIN ADC3_IO_PIN
#define ADC_BAT_BIN ADC4_IO_PIN
#define ADC_CH_GAP ADC_CHANNEL_1
#define ADC_CH_BM ADC_CHANNEL_2
#define ADC_CH_TM ADC_CHANNEL_3
#define ADC_CH_BAT ADC_CHANNEL_4
//DEBUG涓插彛閰?
#define UARTBAUD 115200
#define UART0_TX_PORT GPIOA
#define UART0_TX_PIN GPIO_Pin_1
#define UART0_RX_PORT GPIOA
#define UART0_RX_PIN GPIO_Pin_0
//TPH SPI IO
#define TPH_SPI SPI0
#define TPH_SPI_CLK_PORT GPIOB
#define TPH_SPI_CLK_PIN GPIO_Pin_14
#define TPH_SPI_MOSI_PORT GPIOB
#define TPH_SPI_MOSI_PIN GPIO_Pin_13
#define TPH_SPI_CS_PORT GPIOB
#define TPH_SPI_CS_PIN GPIO_Pin_15
#define TPH_STB1_PORT GPIOB
#define TPH_STB1_PIN GPIO_Pin_12 //加热
#define TPH_STB2_PORT GPIOB
#define TPH_STB2_PIN GPIO_Pin_11 //加热
#define TPH_MDEN_PORT GPIOC
#define TPH_MDEN_PIN GPIO_Pin_0
//FLASH SPI_FLASH IO
#define FLASH_SPI SPI1
#define FLASH_SPI_MOSI_PORT GPIOC
#define FLASH_SPI_MOSI_PIN GPIO_Pin_3
#define FLASH_SPI_MISO_PORT GPIOC
#define FLASH_SPI_MISO_PIN GPIO_Pin_5
#define FLASH_SPI_CLK_PORT GPIOC
#define FLASH_SPI_CLK_PIN GPIO_Pin_2
#define FLASH_SPI_CS_PORT GPIOC
#define FLASH_SPI_CS_PIN GPIO_Pin_4
#ifdef USE_LCD_IIC_PORT
//LCD I2C IO
#define LCD_IIC_SDA_PORT GPIOA
#define LCD_IIC_SDA_PIN GPIO_Pin_5
#define LCD_IIC_CLK_PORT GPIOA
#define LCD_IIC_CLK_PIN GPIO_Pin_4
#define LCD_RST_PORT GPIOA
#define LCD_RST_PIN GPIO_Pin_3
#define LCD_CS_PORT GPIOA
#define LCD_CS1_PIN GPIO_Pin_2
//#define LCD_PWR_PORT GPIOB
//#define LCD_PWR_PIN GPIO_Pin_0
#else
#define LCD_SDA_PORT GPIOA
#define LCD_SDA_PINT GPIO_Pin_5
#define LCD_CLK_PORT GPIOA
#define LCD_CLK_PIN GPIO_Pin_4
#define LCD_RST_PORT GPIOA
#define LCD_RST_PIN GPIO_Pin_3 //
#define LCD_CS_PORT GPIOA
#define LCD_CS1_PIN GPIO_Pin_2 // (没有用)
//#define LCD_DC_PORT GPIOA
//#define LCD_DC_PIN GPIO_Pin_15 //rxid -----------rfid
//#define LCD_PWR_PORT GPIOB
//#define LCD_PWR_PIN GPIO_Pin_0 //gap_e3 --------
#endif
#define Head_En_PORT GPIOA
#define Head_En_PIN GPIO_Pin_12 //head_en
//STEP MOTOR
#define STEP_MOTOR_A1_PORT GPIOC
#define STEP_MOTOR_A1_PIN GPIO_Pin_1
#define STEP_MOTOR_A2_PORT GPIOC
#define STEP_MOTOR_A2_PIN GPIO_Pin_10
#define STEP_MOTOR_B1_PORT GPIOC
#define STEP_MOTOR_B1_PIN GPIO_Pin_12
#define STEP_MOTOR_B2_PORT GPIOC
#define STEP_MOTOR_B2_PIN GPIO_Pin_11
#define STEP_MOTOR_EN_PORT GPIOA
#define STEP_MOTOR_EN_PIN GPIO_Pin_11
#define TPH_POWER_EN_PORT GPIOA
#define TPH_POWER_EN_PIN GPIO_Pin_11
// SERSOR IO
// 测试纸张位置的传感器
#define gap_e3_port GPIOB
#define gap_e3_pin GPIO_Pin_0 //gap_e3
#define gap_e2_port GPIOB
#define gap_e2_pin GPIO_Pin_5 //gap_e2
#define BM_E0_PORT GPIOB
#define BM_E0_PIN GPIO_Pin_6 //gap_e1
#define BM_E1_PORT GPIOB
#define BM_E1_PIN GPIO_Pin_10 //gap_e0
#define KEY_WAKE_PORT GPIOA
#define KEY_WAKE_PIN GPIO_Pin_13
#define KEY_SET_PORT GPIOA
#define KEY_SET_PIN GPIO_Pin_7
#define SYS_POWER_EN_PORT GPIOA //上电输出高
#define SYS_POWER_EN_PIN GPIO_Pin_9
//CHARGE-GET
#define PIN_CHARGE_STATE GPIO_Pin_8
#define PORT_CHARGE_STATE GPIOA
//#define SysTimerInt TIMER4_IRQHandler
//#define PrtTimerInt TIMER3_IRQHandler
//#define LFMotorInt TIMER2_IRQHandler
#endif
// system.c ..........
/*
File Name : system.c
Author : Yichip
Version : V1.0
Date : 2019/12/4
Description : none.
*/
#include <stdarg.h>
#include "system.h"
#include "app.h"
//*****************************************************************************
//
//! A simple MyPrintf function supporting \%c, \%d, \%p, \%s, \%u,\%x, and \%X.
//!
//! \param format is the format string.
//! \param ... are the optional arguments, which depend on the contents of the
//! \return None.
//
//*****************************************************************************
static const int8_t *const g_pcHex1 = "0123456789abcdef";
static const int8_t *const g_pcHex2 = "0123456789ABCDEF";
#ifdef ENABLE_PERIAL_TEST
extern uint8_t uart_printf_switch_gloab;
#endif
void printfsend(UART_TypeDef UARTx, uint8_t *buf, int len)
{
uint8_t printbuf[256];
for (int i = 0; i < len; i++)
{
printbuf[i] = buf[i];
}
#ifdef ENABLE_PERIAL_TEST
if (uart_printf_switch_gloab)
{
UART_SendBuf(UART1, printbuf, len);
}
else
{
UART_SendBuf(UART0, printbuf, len);
}
#else
UART_SendBuf(UARTx, printbuf, len);
#endif
}
static SemaphoreHandle_t UARTMutexHandle = NULL;
void MyPrintf(char *format, ...)
{
#ifdef DEBUG_MSG_ENABLE
extern BOOL initFlag;
uint32_t ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg;
int8_t *pcStr, pcBuf[16], cFill;
char HexFormat;
va_list vaArgP;
va_start(vaArgP, format);
if(initFlag)
{
if(UARTMutexHandle == NULL)
{
UARTMutexHandle = xSemaphoreCreateMutex();
}
if(xSemaphoreTake(UARTMutexHandle, 10000) != pdTRUE)
{
return;
}
}
while (*format)
{
// Find the first non-% character, or the end of the string.
for (ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0'); ulIdx++)
{}
// Write this portion of the string.
if (ulIdx > 0)
{
// printfsend(UART0,format, ulIdx);
printfsend(UART0, (uint8_t *)format, ulIdx);
}
format += ulIdx;
if (*format == '%')
{
format++;
// Set the digit count to zero, and the fill character to space
// (i.e. to the defaults).
ulCount = 0;
cFill = ' ';
again:
switch (*format++)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
if ((format[-1] == '0') && (ulCount == 0))
{
cFill = '0';
}
ulCount *= 10;
ulCount += format[-1] - '0';
goto again;
}
case 'c':
{
ulValue = va_arg(vaArgP, unsigned long);
// printfsend(UART0,(char *)&ulValue, 1);
printfsend(UART0, (uint8_t *)&ulValue, 1);
break;
}
case 'd':
{
ulValue = va_arg(vaArgP, unsigned long);
ulPos = 0;
if ((long)ulValue < 0)
{
ulValue = -(long)ulValue;
ulNeg = 1;
}
else
{
ulNeg = 0;
}
ulBase = 10;
goto convert;
}
case 's':
{
// pcStr = va_arg(vaArgP, char *);
pcStr = (int8_t *)va_arg(vaArgP, char *);
for (ulIdx = 0; pcStr[ulIdx] != '\0'; ulIdx++)
{}
// printfsend(UART0,pcStr, ulIdx);
printfsend(UART0, (uint8_t *)pcStr, ulIdx);
if (ulCount > ulIdx)
{
ulCount -= ulIdx;
while (ulCount--)
{
// printfsend(UART0, " ", 1);
printfsend(UART0, (uint8_t *)" ", 1);
}
}
break;
}
case 'u':
{
ulValue = va_arg(vaArgP, unsigned long);
ulPos = 0;
ulBase = 10;
ulNeg = 0;
goto convert;
}
case 'X':
{
ulValue = va_arg(vaArgP, unsigned long);
ulPos = 0;
ulBase = 16;
ulNeg = 0;
HexFormat = 'X';
goto convert;
}
case 'x':
case 'p':
{
ulValue = va_arg(vaArgP, unsigned long);
ulPos = 0;
ulBase = 16;
ulNeg = 0;
HexFormat = 'x';
convert:
for (ulIdx = 1;
(((ulIdx * ulBase) <= ulValue) &&
(((ulIdx * ulBase) / ulBase) == ulIdx));
ulIdx *= ulBase, ulCount--)
{
}
if (ulNeg)
{
ulCount--;
}
if (ulNeg && (cFill == '0'))
{
pcBuf[ulPos++] = '-';
ulNeg = 0;
}
if ((ulCount > 1) && (ulCount < 16))
{
for (ulCount--; ulCount; ulCount--)
{
pcBuf[ulPos++] = cFill;
}
}
if (ulNeg)
{
pcBuf[ulPos++] = '-';
}
for (; ulIdx; ulIdx /= ulBase)
{
if (HexFormat == 'x')
pcBuf[ulPos++] = g_pcHex1[(ulValue / ulIdx) % ulBase];//x
else
pcBuf[ulPos++] = g_pcHex2[(ulValue / ulIdx) % ulBase];//X
}
// printfsend(UART0, pcBuf, ulPos);
printfsend(UART0, (uint8_t *)pcBuf, ulPos);
break;
}
case '%':
{
// printfsend(UART0, format - 1, 1);
printfsend(UART0, (uint8_t *)format - 1, 1);
break;
}
default:
{
// printfsend(UART0, "ERROR", 5);
printfsend(UART0, (uint8_t *)"ERROR", 5);
break;
}
}//switch
}//if
}//while
va_end(vaArgP);
if(initFlag)
{
xSemaphoreGive(UARTMutexHandle);
}
#endif
}
void printv(uint8_t *buf, uint32_t len, uint8_t *s)
{
uint32_t i = 0;
uint32_t n = 0;
MyPrintf("\r\n %s:", s);
for (i = 0; i < len; i++)
{
if (i % 16 == 0)
{
MyPrintf("\r\n%08x:", n);
n += 16;
}
MyPrintf("%02x ", buf[i]);
}
}
void _assert_handler(const char *file, int line, const char *func)
{
#if defined (SDK_DEBUG)
MyPrintf("Assert trigger at file: %s line:%d func: %s\n ", file, line, func);
#endif
while (1);
}
// type.h
/*
File Name : type.h
Author : Yichip
Version : V1.0
Date : 2018/05/25
Description : Data type definition.
*/
#ifndef __TYPE_H__
#define __TYPE_H__
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned char byte;
typedef unsigned short word;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
#define STATIC static
#define DWORD uint32_t
#define WORD uint32_t
#define BYTE uint8_t
#define VOID void
#define INT int32_t
#define UINT uint32_t
#define FLOAT float
#define SHORT int16_t
#define CONST const
typedef struct BitChar {
unsigned B0:1;//固定为1
unsigned B1:1;//固定为0
unsigned B2:1;//正在执行打印
unsigned B3:1;//打印完毕
unsigned B4:1;//打印机有错误(包括:缺纸、上盖、机头过热、写RFID出错);
unsigned B5:1;//暂停状态
unsigned B6:1;//打印内容被取消
unsigned B7:1;//保留
} SBitChar;
typedef struct Bitshort {
unsigned B0: 1;//固定为1
unsigned B1: 1;//固定为0
unsigned B2: 1;//缺纸
unsigned B3: 1;//上盖打开
unsigned B4: 1;//机芯异常
unsigned B5: 1;//打印头过热
unsigned B6: 1;//插入碳带不可识别
unsigned B7: 1;//碳带用尽
unsigned B8: 1;//写RFID出错
unsigned B9: 1;//剪切出错
unsigned B10:1;//打印异常(堵转)
unsigned B11:1;//电池电量过低
unsigned B12:1;//未检测到标签
unsigned B13:1;
unsigned B14:1;
unsigned B15:1;
} SBitshort;
typedef union CharField{
unsigned char byte;
SBitChar field;
} UCharField;
typedef union shortField{
unsigned char byte[2];
SBitshort field;
} UshortField;
#define RCV_TYPE_BLE 0
#define RCV_TYPE_SPP 1
#define RCV_TYPE_USB 2
#define RCV_TYPE_UART 3
#define NO_PAPER 0
#define FULL_PAPER 1
#define GAP_PAPER 2
#define FULL_TO_FULL_PAPER 0x11
#define FULL_TO_GAP_PAPER 0x12
#define GAP_TO_FULL_PAPER 0x21
#define GAP_TO_GAP_PAPER 0x22
#define GAP_ADJ_COUNT_MAX 4
#define POWER_OFF_DELAY 60000
//#define USE_NO_PAPER_DET
#define USE_BLE
#define USE_BAT_DET
//#define USE_PAUSE_KEY
#define USE_LCD
#define USE_PWM_BEEP
#define USE_LCD_IIC_PORT
#ifndef Boolean
typedef enum {FALSE = 0, TRUE = 1} Boolean;
#define IS_BOOLEAN(bool) ((bool == FALSE) || (bool == TRUE))
#endif
#ifndef FunctionalState
typedef enum {DISABLE = 0, ENABLE = 1} FunctionalState;
#define IS_FUNCTIONAL_STATE(state) ((state== DISABLE) || (state == ENABLE))
#endif
#ifndef FunctionalState
typedef enum {ERROR = 0, SUCCESS = 1} ErrorStatus;
#define IS_ERROR_STATE(status) ((status== ERROR) || (status == SUCCESS))
#endif
#ifndef FlagStatus
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
#endif
#endif /*__TYPE_H__*/
// YC3121_PT26\ConfigFiles\MDK flash.ini
FUNC void Setup(void)
{
SP = 0x30000;
PC = 0x1000200;
}
Setup();
PT26_存在的差异文件
最新推荐文章于 2024-08-20 14:05:47 发布