nwxt appr. to canusbrelay

This commit is contained in:
Edward Emelianov
2021-07-23 23:37:52 +03:00
parent 813549e0f2
commit 4fc13b2b11
21 changed files with 647 additions and 7988 deletions

View File

@@ -1,12 +1,10 @@
/*
* geany_encoding=koi8-r
* hardware.h
* This file is part of the canrelay project.
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -15,17 +13,25 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
#include <stm32f0.h>
#define SYSMEM03x 0x1FFFEC00
#define SYSMEM04x 0x1FFFC400
#define SYSMEM05x 0x1FFFEC00
#define SYSMEM07x 0x1FFFC800
#define SYSMEM09x 0x1FFFD800
// define SystemMem to other in MAKEFILE
#ifndef SystemMem
#define SystemMem SYSMEM04x
#endif
#define CONCAT(a,b) a ## b
#define STR_HELPER(s) #s
#define STR(s) STR_HELPER(s)
@@ -33,29 +39,36 @@
#define FORMUSART(X) CONCAT(USART, X)
#define USARTX FORMUSART(USARTNUM)
// LEDS: 0 - PB0, 1 - PB1
// LED0
#define LED0_port GPIOB
#define LED0_pin (1<<0)
// LED1
#define LED1_port GPIOB
#define LED1_pin (1<<1)
// LEDs amount
#define LEDSNO (4)
// LEDs ports & pins
extern GPIO_TypeDef *LEDports[LEDSNO];
extern const uint32_t LEDpins[LEDSNO];
// LEDS: 0 - PB12, 1 - PB13, 2 - PB14, 3 - PB15
#define LED_toggle(x) do{pin_toggle(LEDports[x], LEDpins[x]);}while(0)
#define LED_on(x) do{pin_clear(LEDports[x], LEDpins[x]);}while(0)
#define LED_off(x) do{pin_set(LEDports[x], LEDpins[x]);}while(0)
#define LED_blink(x) do{if(ledsON) pin_toggle(x ## _port, x ## _pin);}while(0)
#define LED_on(x) do{if(ledsON) pin_clear(x ## _port, x ## _pin);}while(0)
#define LED_off(x) do{pin_set(x ## _port, x ## _pin);}while(0)
// Buttons amount
#define BTNSNO (4)
// Buttons ports & pins
extern GPIO_TypeDef *BTNports[BTNSNO];
extern const uint32_t BTNpins[BTNSNO];
// state 1 - pressed, 0 - released
#define BTN_state(x) ((BTNports[x]->IDR & BTNpins[x]) ? 0 : 1)
// mask for PB0..7
#define CAN_INV_ID_MASK (0xff)
// CAN address - PB0..7
#define READ_INV_CAN_ADDR() (GPIOB->IDR & 0xff)
// CAN address - PB14(0), PB15(1), PA8(2)
#define READ_CAN_INV_ADDR() (((GPIOA->IDR & (1<<8))>>6)|((GPIOB->IDR & (3<<14))>>14))
extern uint16_t CANID; // self CAN ID (read @ init)
extern volatile uint32_t Tms;
extern uint8_t ledsON;
void gpio_setup(void);
void iwdg_setup();
void tim1_setup();
void pause_ms(uint32_t pause);
void Jump2Boot();