add src STS/RC

This commit is contained in:
Yunhorn 2025-07-11 16:16:00 +08:00
parent 0aed02050c
commit 0027a4d285
9 changed files with 876 additions and 0 deletions

169
STS/RC/i2c_hal.c Normal file
View File

@ -0,0 +1,169 @@
//-- Includes -----------------------------------------------------------------
#include "i2c_hal.h"
#include "main.h"
#include "stdio.h"
//-- Defines ------------------------------------------------------------------
// I2C IO-Pins /* -- adapt the defines for your uC -- */
// SDA on port A, bit 10
/*
#define SDA_LOW() (GPIOA->BSRR = 0x04000000) // set SDA to low
#define SDA_OPEN() (GPIOA->BSRR = 0x00000400) // set SDA to open-drain
#define SDA_READ (GPIOA->IDR & 0x0400) // read SDA
*/
// SCL on port A, bit 9 /* -- adapt the defines for your uC -- */
/*
#define SCL_LOW() (GPIOA->BSRR = 0x02000000) // set SCL to low
#define SCL_OPEN() (GPIOA->BSRR = 0x00000200) // set SCL to open-drain
#define SCL_READ (GPIOA->IDR & 0x0200) // read SCL
*/
// 2025 07 10 for SHT3X STM32WLE5CCU6
// SDA on port A, bit 11
#define SDA_LOW() (GPIOA->BSRR = 0x080000000) // set SDA to low
#define SDA_OPEN() (GPIOA->BSRR = 0x00000800) // set SDA to open-drain
#define SDA_READ (GPIOA->IDR & 0x0800) // read SDA
// SCL on port A, bit 12 /* -- adapt the defines for your uC -- */
#define SCL_LOW() (GPIOA->BSRR = 0x10000000) // set SCL to low
#define SCL_OPEN() (GPIOA->BSRR = 0x00001000) // set SCL to open-drain
#define SCL_READ (GPIOA->IDR & 0x1000) // read SCL
//-- Static function prototypes -----------------------------------------------
static etError I2c_WaitWhileClockStreching(u8t timeout);
//-----------------------------------------------------------------------------
void I2c_Init(void) /* -- adapt the init for your uC -- */
{
GPIO_InitTypeDef GPIO_InitStructure;
// RCC->APB2ENR |= 0x00000008; // I/O port B clock enabled
RCC->APB2ENR |= 0x00000004; // I/O port A clock enabled
GPIO_InitStructure.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
SDA_OPEN(); // I2C-bus idle mode SDA released
SCL_OPEN(); // I2C-bus idle mode SCL released
/*
LL_GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = (LL_GPIO_PIN_9 | LL_GPIO_PIN_10);
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
*/
}
//-----------------------------------------------------------------------------
void I2c_StartCondition(void)
{
SDA_OPEN();
DelayMicroSeconds(1);
SCL_OPEN();
DelayMicroSeconds(1);
SDA_LOW();
DelayMicroSeconds(10); // hold time start condition (t_HD;STA)
SCL_LOW();
DelayMicroSeconds(10);
}
//-----------------------------------------------------------------------------
void I2c_StopCondition(void)
{
SCL_LOW();
DelayMicroSeconds(1);
SDA_LOW();
DelayMicroSeconds(1);
SCL_OPEN();
DelayMicroSeconds(10); // set-up time stop condition (t_SU;STO)
SDA_OPEN();
DelayMicroSeconds(10);
}
//-----------------------------------------------------------------------------
etError I2c_WriteByte(u8t txByte)
{
etError error = NO_ERROR;
u8t mask;
for(mask = 0x80; mask > 0; mask >>= 1)// shift bit for masking (8 times)
{
if((mask & txByte) == 0) SDA_LOW(); // masking txByte, write bit to SDA-Line
else SDA_OPEN();
DelayMicroSeconds(1); // data set-up time (t_SU;DAT)
SCL_OPEN(); // generate clock pulse on SCL
DelayMicroSeconds(5); // SCL high time (t_HIGH)
SCL_LOW();
DelayMicroSeconds(1); // data hold time(t_HD;DAT)
}
SDA_OPEN(); // release SDA-line
SCL_OPEN(); // clk #9 for ack
DelayMicroSeconds(1); // data set-up time (t_SU;DAT)
if(SDA_READ) error = ACK_ERROR; // check ack from i2c slave
SCL_LOW();
DelayMicroSeconds(20); // wait to see byte package on scope
return error; // return error code
}
//-----------------------------------------------------------------------------
etError I2c_ReadByte(u8t *rxByte, etI2cAck ack, u8t timeout)
{
etError error = NO_ERROR;
u8t mask;
*rxByte = 0x00;
SDA_OPEN(); // release SDA-line
for(mask = 0x80; mask > 0; mask >>= 1) // shift bit for masking (8 times)
{
SCL_OPEN(); // start clock on SCL-line
DelayMicroSeconds(1); // clock set-up time (t_SU;CLK)
error = I2c_WaitWhileClockStreching(timeout);// wait while clock streching
DelayMicroSeconds(3); // SCL high time (t_HIGH)
if(SDA_READ) *rxByte |= mask; // read bit
SCL_LOW();
DelayMicroSeconds(1); // data hold time(t_HD;DAT)
}
if(ack == ACK) SDA_LOW(); // send acknowledge if necessary
else SDA_OPEN();
DelayMicroSeconds(1); // data set-up time (t_SU;DAT)
SCL_OPEN(); // clk #9 for ack
DelayMicroSeconds(5); // SCL high time (t_HIGH)
SCL_LOW();
SDA_OPEN(); // release SDA-line
DelayMicroSeconds(20); // wait to see byte package on scope
return error; // return with no error
}
//-----------------------------------------------------------------------------
etError I2c_GeneralCallReset(void)
{
etError error;
I2c_StartCondition();
error = I2c_WriteByte(0x00);
if(error == NO_ERROR) error = I2c_WriteByte(0x06);
return error;
}
//-----------------------------------------------------------------------------
static etError I2c_WaitWhileClockStreching(u8t timeout)
{
etError error = NO_ERROR;
while(SCL_READ == 0)
{
if(timeout-- == 0) return TIMEOUT_ERROR;
DelayMicroSeconds(1000);
}
return error;
}

73
STS/RC/i2c_hal.h Normal file
View File

@ -0,0 +1,73 @@
//=============================================================================
// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//=============================================================================
// Project : SHT3x Sample Code (V1.1)
// File : i2c_hal.h (V1.1)
// Author : RFU
// Date : 6-Mai-2015
// Controller: STM32F100RB
// IDE : µVision V5.12.0.0
// Compiler : Armcc
// Brief : I2C hardware abstraction layer
//=============================================================================
#ifndef I2C_HAL_H
#define I2C_HAL_H
//-- Includes -----------------------------------------------------------------
#include "system.h"
//-- Enumerations -------------------------------------------------------------
// I2C acknowledge
typedef enum{
ACK = 0,
NACK = 1,
}etI2cAck;
//=============================================================================
void I2c_Init(void);
//=============================================================================
// Initializes the ports for I2C interface.
//-----------------------------------------------------------------------------
//=============================================================================
void I2c_StartCondition(void);
//=============================================================================
// Writes a start condition on I2C-Bus.
//-----------------------------------------------------------------------------
// remark: Timing (delay) may have to be changed for different microcontroller.
// _____
// SDA: |_____
// _______
// SCL: |___
//=============================================================================
void I2c_StopCondition(void);
//=============================================================================
// Writes a stop condition on I2C-Bus.
//-----------------------------------------------------------------------------
// remark: Timing (delay) may have to be changed for different microcontroller.
// _____
// SDA: _____|
// _______
// SCL: ___|
//=============================================================================
etError I2c_WriteByte(u8t txByte);
//=============================================================================
// Writes a byte to I2C-Bus and checks acknowledge.
//-----------------------------------------------------------------------------
// input: txByte transmit byte
//
// return: error: ACK_ERROR = no acknowledgment from sensor
// NO_ERROR = no error
//
// remark: Timing (delay) may have to be changed for different microcontroller.
//=============================================================================
etError I2c_ReadByte(u8t *rxByte, etI2cAck ack, u8t timeout);
etError I2c_GeneralCallReset(void);
#endif

169
STS/RC/sht3x.c Normal file
View File

@ -0,0 +1,169 @@
//-- Includes -----------------------------------------------------------------
#include "sht3x.h"
//-- Defines ------------------------------------------------------------------
// Generator polynomial for CRC
#define POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001
static uint8_t SHT3x_Send_Data(SHT3x_CMD cmd);
static uint8_t SHT3x_Readout_Data(uint8_t *receive_original_data);
static float SHT3X_CalcTemperature(uint16_t rawValue);
static float SHT3X_CalcHumidity(uint16_t rawValue);
SHT3x_ReadData SHT3x_Data = {0.0, 0.0};
extern I2C_HandleTypeDef hi2c2;
#define I2Cx hi2c2
/**
* @function: static uint8_t SHT3x_Send_Data(SHT3x_CMD cmd)
* @description: SHT3x发送数据
* @param {SHT3x_CMD}cmd待发送的指令数据
* @return {0}
* @return {1}
*/
static uint8_t SHT3x_Send_Data(SHT3x_CMD cmd)
{
uint8_t cmd_buf[2];
cmd_buf[0] = cmd >> 8;
cmd_buf[1] = cmd;
#if SHT3X_USING_HARDWARE_I2C
if (HAL_I2C_IsDeviceReady(&I2Cx, SHT3X_ADDRESS, 100, 1000))
return 1;
if (HAL_I2C_Master_Transmit(&I2Cx, SHT3X_ADDRESS, cmd_buf, 2, HAL_MAX_DELAY))
return 1;
return 0;
#endif
}
/**
* @function: uint8_t SHT3x_Soft_Reset(void)
* @description: SHT3x软件复位
* @param {*}
* @return {0}
* @return {1}
*/
uint8_t SHT3x_Soft_Reset(void)
{
if (SHT3x_Send_Data(SOFT_RESET))
return 1;
SHT3x_Delay_ms(10);
return 0;
}
/**
* @function: uint8_t SHT3x_Init_Measurement_Mode(SHT3x_CMD Mode)
* @description: SHT3x测量模式设置
* @param {SHT3x_CMD} Mode
* @return {0}
* @return {1}
*/
uint8_t SHT3x_Init_Measurement_Mode(SHT3x_CMD Mode)
{
if (SHT3x_Send_Data(Mode))
return 1;
return 0;
SHT3x_Delay_ms(20);
}
/**
* @function: static uint8_t SHT3x_Readout_Data(uint8_t *receive_original_data)
* @description: SHT3x周期模式读取数据
* @param {uint8_t} *receive_original_data读取的数据6byte
* @return {0}
* @return {1}
*/
static uint8_t SHT3x_Readout_Data(uint8_t *receive_original_data)
{
#if SHT3X_USING_HARDWARE_I2C
if (HAL_I2C_IsDeviceReady(&I2Cx, SHT3X_ADDRESS, 100, 1000))
return 2;
SHT3x_Send_Data(FETCH_DATA_PERIODIC);
SHT3x_Delay_ms(20);
if (HAL_I2C_Master_Receive(&I2Cx, SHT3X_ADDRESS, receive_original_data, 6, HAL_MAX_DELAY))
return 1;
return 0;
#endif
}
/**
* @function: uint8_t SHT3x_Get_TemperatureHumidity(void)
* @description: SHT3x温湿度读取
* @param {*}
* @return {0}
* @return {1}
*/
uint8_t SHT3x_Get_TemperatureHumidity(float *temperature, float *humidity)
{
uint8_t raw_data[6];
uint16_t raw_temperature = 0;
uint16_t raw_humidity = 0;
SHT3x_Readout_Data(raw_data);
if (CRC8_Calculation(raw_data, 0xFF) != raw_data[2] ||
CRC8_Calculation(&raw_data[3], 0xFF) != raw_data[5])
return 1;
// /*温度转换*/
raw_temperature = ((uint16_t)raw_data[0] << 8) | raw_data[1];
// Temperature = -49 + 315 * ((float)original_temperature / 65535);//华氏度°F
//*temperature = (int)(-45.0 + (float)175.0 * ((float)raw_temperature / 65535)); //摄氏度°C
*temperature = SHT3X_CalcTemperature(raw_temperature);
/*湿度转换*/
raw_humidity = ((uint16_t)raw_data[3] << 8) | raw_data[4];
//SHT3x_Data.SHT3x_Humidity = 100 * ((float)original_humidity / 65535);
//*humidity = (int)(100.0 * ((float)raw_humidity / 65535));
*humidity = SHT3X_CalcHumidity(raw_humidity);
return 0;
}
//-----------------------------------------------------------------------------
static float SHT3X_CalcTemperature(uint16_t rawValue)
{
// calculate temperature [<5B>C]
// T = -45 + 175 * rawValue / (2^16-1)
return (float)(175.0f * (float)rawValue / 65535.0f - 45.0f);
}
//-----------------------------------------------------------------------------
static float SHT3X_CalcHumidity(uint16_t rawValue)
{
// calculate relative humidity [%RH]
// RH = rawValue / (2^16-1) * 100
return (float)(100.0f * (float)rawValue / 65535.0f);
}
/**
* @function: uint8_t CRC8_Calculation(uint8_t *const message, uint8_t initial_value)
* @description: CRC8的校验计算
* @param {uint8_t} *const message带校验数据信息
* @param {uint8_t} initial_value设定初值0xFF
* @return {uint8_t}remainder计算的CRC码
*/
uint8_t CRC8_Calculation(uint8_t *const message, uint8_t initial_value)
{
const uint8_t CRC8_POLYNOMIAL = 0x31;
uint8_t remainder; //余数
uint8_t i = 0, j = 0; //循环变量
/* 初始化 */
remainder = initial_value;
for (j = 0; j < 2; j++)
{
remainder ^= message[j];
/* 从最高位开始依次计算 */
for (i = 0; i < 8; i++)
{
if (remainder & 0x80)
{
remainder = (remainder << 1) ^ CRC8_POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
}
/* 返回计算的CRC码 */
return remainder;
}

101
STS/RC/sht3x.h Normal file
View File

@ -0,0 +1,101 @@
#ifndef __SHT3X_H__
#define __SHT3X_H__
#ifdef __cplusplus
extern "C"{
#endif
#include "main.h"
#define SHT3X_USING_HARDWARE_I2C 1 //使用硬件i2c
#if SHT3X_USING_HARDWARE_I2C
#include "i2c.h"
//#define I2Cx hi2c2
#endif
#define SHT3X_ADDRESS (0x44 << 1) //ADDR-->GND(0x44<<1)/ADDR-->VCC(0x45<<1)
//读取的温湿度数据
typedef struct SHT3x_TemperatureHumidity
{
float SHT3x_Temperature;
float SHT3x_Humidity;
} SHT3x_ReadData;
extern SHT3x_ReadData SHT3x_Data;
//SHT3x相关指令
typedef enum
{
/**
*
**/
SOFT_RESET = 0x30A2,
/**
*
* (Repeatability)
* 使/(Clock stretching)(:SCL总线将一直为低电平)
**/
SINGLE_HIGH_ENABLE = 0x2C06,
SINGLE_MEDIUM_ENABLE = 0x2C0D,
SINGLE_LOW_ENABLE = 0x2C10,
SINGLE_HIGH_DISABLE = 0x2400,
SINGLE_MEDIUM_DISABLE = 0x240B,
SINGLE_LOW_DISABLE = 0x2416,
/**
*
* (Repeatability)
* 0.5/1/2/4/10(measurements per second)
**/
PERIODIC_HIGH_0_5 = 0x2032,
PERIODIC_MEDIUM_0_5 = 0x2024,
PERIODIC_LOW_0_5 = 0x202F,
PERIODIC_HIGH_1 = 0x2130,
PERIODIC_MEDIUM_1 = 0x2126,
PERIODIC_LOW_1 = 0x212D,
PERIODIC_HIGH_2 = 0x2236,
PERIODIC_MEDIUM_2 = 0x2220,
PERIODIC_LOW_2 = 0x222B,
PERIODIC_HIGH_4 = 0x2334,
PERIODIC_MEDIUM_4 = 0x2322,
PERIODIC_LOW_4 = 0x2329,
PERIODIC_HIGH_10 = 0x2737,
PERIODIC_MEDIUM_10 = 0x2721,
PERIODIC_LOW_10 = 0x272A,
/**
*
**/
FETCH_DATA_PERIODIC = 0xE000,
/**
* /
**/
BREAK_ACQUISITION_DATA = 0x3093,
/**
*
**/
HEATER_ENABLE = 0x306D,
HEATER_DISABLE = 0x3066,
/**
*
**/
READ_STATUS_REGISTER = 0xF32D,
/**
*
**/
CLEAR_STATUS_REGISTER = 0x3041,
/**
* ART加速响应时间命令
**/
ACCELERATED_RESPONSE_TIME = 0x2B32
} SHT3x_CMD;
#define SHT3x_Delay_ms(__xms) HAL_Delay(__xms)
uint8_t SHT3x_Soft_Reset(void);
uint8_t SHT3x_Init_Measurement_Mode(SHT3x_CMD Mode);
uint8_t SHT3x_Get_TemperatureHumidity(float *temperature, float *humidity);
uint8_t CRC8_Calculation(uint8_t *const message, uint8_t initial_value);
#ifdef __cplusplus
}
#endif
#endif //__SHT3X_H__

136
STS/RC/sts_remote_control.c Normal file
View File

@ -0,0 +1,136 @@
/**
******************************************************************************
* @file sts_remote_control.c *
* @author Yunhorn (r) Technology Limited Application Team *
* @brief Yunhorn (r) SmarToilets (r) HMAC-SHA1 Process file. *
******************************************************************************
* @attention
*
* Copyright (c) 2023 Yunhorn Technology Limited.
* Copyright (c) 2023 Shenzhen Yunhorn Technology Co., Ltd.
* All rights reserved.
******************************************************************************
*/
#include "main.h"
#include "sts_remote_control.h"
#include "yunhorn_sts_prd_conf.h"
#include "yunhorn_sts_sensors.h"
service_period_per_day_t rc_service_period[4] = {
{0x1f, 6, 30, 12, 00},
{0x60, 13, 00, 18, 00},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}};
static bool sts_rc_in_service_period = true;
static void STS_Check_Service_Period(void)
{
struct tm time_now = {0};
SysTime_t UnixEpoch = SysTimeGet();
UnixEpoch.Seconds -= 18; /*removing leap seconds*/
SysTimeLocalTime(UnixEpoch.Seconds, &time_now);
bool sts_rc_in_service_period_try = false;
for (uint8_t i = 0; i < 4; i++)
{
if (rc_service_period[i].enable)
{
if ((time_now.tm_hour >= rc_service_period[i].start_hour) && (time_now.tm_hour < rc_service_period[i].end_hour))
{
sts_rc_in_service_period_try = true;
}
}
}
sts_rc_in_service_period = sts_rc_in_service_period_try;
}
extern uint8_t rf_payload[3];
/*
* measure humidity --> over threshold --> caution wet floor + power on()
* measure humidity --> not over threshold --> welcome pic or power off
* button- switch 1:power off ---> power off
* button- switch 2/1: local control ? via internal sensor
* button- switch 2/2: cloud control ?
* key_name --> 1/2/3/4/5/6/7/8 or ON/OFF/FIRST/NEXT/5S/10S/15S/30S
* cmd_value---> key2cmd[key_name] 0x01,0x08,0x0c,0x
*
*/
static void SendRemoteControlData(void)
{
/* sts_rf_cmd_status: global cmd process status */
/* */
switch (sts_rf_cmd_status)
{
case STS_NODESELF_CMD_PENDING_SEND:
if (sts_rf_projector_power_on == true)
// rf_payload[2] |= rf_button_2_cmd4bits[sts_rc_cmd_value];
STS_RF_Send_Button_Multi_Times(rf_payload, sts_rf_cmd_value);
sts_rf_cmd_status = STS_RF_CMD_SENT_OUT;
break;
case STS_CLOUD_CMD_PENDING_SEND: // CLOUD DOWNLINK INSTRUCTION
if (sts_rf_cloud_cmd == BUTTON_OFF) // if ask to power off
{
sts_rf_cmd_value = BUTTON_OFF;
// rf_payload[2] |= rf_button_2_cmd4bits[sts_rc_cmd_value]; //rf_cmd[BUTTON_ON];//sts_rf_cloud_cmd;
sts_rf_projector_power_on = false;
}
else
{ // else other show pic cmd
if (sts_rf_projector_power_on == false) // if it's still powered off yet, power it on
{
sts_rf_cmd_value = BUTTON_ON;
// rf_payload[2] |= rf_button_2_cmd4bits[sts_rc_cmd_value];
STS_RF_Send_Button_Multi_Times(rf_payload, sts_rf_cloud_cmd);
sts_rf_projector_power_on = true;
HAL_Delay(2000); // need to test 2 sec good enough or not... maybe 30 seconds...
} // delay 2 sec, then send cloud cmd...
// rf_payload[2] |= rf_button_2_cmd4bits[sts_rc_cloud_cmd];
STS_RF_Send_Button_Multi_Times(rf_payload, sts_rf_cloud_cmd);
}
sts_rf_cmd_status = STS_RF_CMD_SENT_OUT;
break;
case STS_RF_CMD_SENT_OUT:
// Do nothing
break;
case STS_RF_CMD_NONE:
// No cmd to send out
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
}
}
/* end of sts_remote_control.c*/

View File

@ -0,0 +1,37 @@
/**
******************************************************************************
* @file sts_remote_control.h *
* @author Yunhorn (r) Technology Limited Application Team *
* @brief Yunhorn (r) SmarToilets (r) HMAC-SHA1 Process file. *
******************************************************************************
* @attention
*
* Copyright (c) 2023 Yunhorn Technology Limited.
* Copyright (c) 2023 Shenzhen Yunhorn Technology Co., Ltd.
* All rights reserved.
******************************************************************************
*/
#include "main.h"
#include "yunhorn_sts_prd_conf.h"
#include "yunhorn_sts_sensors.h"
typedef struct service_period_per_day
{
uint8_t enable_mask; // enable this time slot or not day of week,
// 0x1f= 0b0001 1111 ---> day1 to day5 of week
// 0x60= 0b0110 0000 ---> day6 5o day 7 of week
uint8_t start_hour; // start hour 00--23 in 24hour
uint8_t start_minute; // start minute 00--59
uint8_t end_hour; // end hour 00-23 in 24 hour
uint8_t end_minute; // end minute 00--60
} service_period_t;
#define STS_RF_PROJECTOR_PENDING_SEND 1U
#define STS_RF_PROJECTOR_POWER_OFF 2
#define STS_RF_SHOW_PIC_DARK 0
#define STS_RF_SHOW_PIC_WET_FLOOR 4U
#define STS_RF_SHOW_PIC_WELCOME 5
#define STS_RF_PROJECTOR_KEEP_STATE 0
/* end of sts_remote_control.h*/

52
STS/RC/system.c Normal file
View File

@ -0,0 +1,52 @@
//=============================================================================
// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//=============================================================================
// Project : SHT3x Sample Code (V1.1)
// File : system.c (V1.1)
// Author : RFU
// Date : 6-Mai-2015
// Controller: STM32F100RB
// IDE : µVision V5.12.0.0
// Compiler : Armcc
// Brief : System functions
//=============================================================================
//-- Includes -----------------------------------------------------------------
#include "system.h"
//-----------------------------------------------------------------------------
//void SystemInit(void)
//{
// // no initialization required
//}
//-----------------------------------------------------------------------------
void DelayMicroSeconds(u32t nbrOfUs) /* -- adapt this delay for your uC -- */
{
while(nbrOfUs)
{
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
__NOP();__NOP();
nbrOfUs--;
}
}

70
STS/RC/system.h Normal file
View File

@ -0,0 +1,70 @@
//=============================================================================
// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//=============================================================================
// Project : SHT3x Sample Code (V1.1)
// File : system.h (V1.1)
// Author : RFU
// Date : 6-Mai-2015
// Controller: STM32F100RB
// IDE : <20>Vision V5.12.0.0
// Compiler : Armcc
// Brief : System functions, global definitions
//=============================================================================
#ifndef SYSTEM_H
#define SYSTEM_H
//-- Includes -----------------------------------------------------------------
#include "stm32wlxx.h" // controller register definitions
#include "typedefs.h" // type definitions
#include "main.h"
//-- Enumerations -------------------------------------------------------------
// Error codes
typedef enum{
NO_ERROR = 0x00, // no error
ACK_ERROR = 0x01, // no acknowledgment error
CHECKSUM_ERROR = 0x02, // checksum mismatch error
TIMEOUT_ERROR = 0x04, // timeout error
PARM_ERROR = 0x80, // parameter out of range error
}etError;
//=============================================================================
void SystemInit(void);
//=============================================================================
// Initializes the system
//-----------------------------------------------------------------------------
//=============================================================================
void DelayMicroSeconds(u32t nbrOfUs);
//=============================================================================
// Wait function for small delays.
//-----------------------------------------------------------------------------
// input: nbrOfUs wait x times approx. one micro second (fcpu = 8MHz)
// return: -
// remark: smallest delay is approx. 15us due to function call
#define SYSTEM_CORE_CLOCK 48000000
#define DBG_TIME
#define DELAY_MS_CLOCK (SYSTEM_CORE_CLOCK - 18) / 11000
#define DELAY_100US_CLOCK (SYSTEM_CORE_CLOCK) / 120600
#define DELAY_10US_CLOCK (SYSTEM_CORE_CLOCK) / 1200000
#define DELAY_1US_CLOCK (SYSTEM_CORE_CLOCK) / 12000000
#define NOP() __ASM volatile ("nop")
void Delay(uint32_t nTime);
void DelayMs(uint32_t mS);
void Delay1Us(uint32_t time);
void Delay10Us(uint32_t time);
void Delay100Us(uint32_t time);
//void USART_Config(void);
void SysTickConfig(void);
#endif

69
STS/RC/typedefs.h Normal file
View File

@ -0,0 +1,69 @@
//=============================================================================
// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//=============================================================================
// Project : SHT3x Sample Code (V1.1)
// File : typedefs.h (V1.1)
// Author : RFU
// Date : 6-Mai-2015
// Controller: STM32F100RB
// IDE : µVision V5.12.0.0
// Compiler : Armcc
// Brief : Definitions of typedefs for good readability and portability.
//=============================================================================
#ifndef TYPEDEFS_H
#define TYPEDEFS_H
//-- Defines ------------------------------------------------------------------
//Processor endian system
//#define BIG ENDIAN //e.g. Motorola (not tested at this time)
#define LITTLE_ENDIAN //e.g. PIC, 8051, NEC V850
//=============================================================================
// basic types: making the size of types clear
//=============================================================================
typedef unsigned char u8t; ///< range: 0 .. 255
typedef signed char i8t; ///< range: -128 .. +127
typedef unsigned short u16t; ///< range: 0 .. 65535
typedef signed short i16t; ///< range: -32768 .. +32767
typedef unsigned long u32t; ///< range: 0 .. 4'294'967'295
typedef signed long i32t; ///< range: -2'147'483'648 .. +2'147'483'647
typedef float ft; ///< range: +-1.18E-38 .. +-3.39E+38
typedef double dt; ///< range: .. +-1.79E+308
typedef enum{
FALSE = 0,
TRUE = 1
}bt;
typedef union {
u16t u16; // element specifier for accessing whole u16
i16t i16; // element specifier for accessing whole i16
struct {
#ifdef LITTLE_ENDIAN // Byte-order is little endian
u8t u8L; // element specifier for accessing low u8
u8t u8H; // element specifier for accessing high u8
#else // Byte-order is big endian
u8t u8H; // element specifier for accessing low u8
u8t u8L; // element specifier for accessing high u8
#endif
} s16; // element spec. for acc. struct with low or high u8
} nt16;
typedef union {
u32t u32; // element specifier for accessing whole u32
i32t i32; // element specifier for accessing whole i32
struct {
#ifdef LITTLE_ENDIAN // Byte-order is little endian
u16t u16L; // element specifier for accessing low u16
u16t u16H; // element specifier for accessing high u16
#else // Byte-order is big endian
u16t u16H; // element specifier for accessing low u16
u16t u16L; // element specifier for accessing high u16
#endif
} s32; // element spec. for acc. struct with low or high u16
} nt32;
#endif