feat(school_stm32): 添加基础的 STM32F103RCT6 项目结构

- 创建了项目的基本目录结构和文件
- 添加了 CMakeLists.txt 和 Makefile 构建配置
- 创建了 main.c 文件,实现了简单的 LED 闪烁和按键检测功能
- 集成了 SEGGER RTT 库
- 添加了 .gitignore 文件,排除了不必要的生成文件
This commit is contained in:
ZZY
2025-06-27 23:09:57 +08:00
parent 5f560c1268
commit 52097a36ee
37 changed files with 7714 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#ifndef __GE_INPUT_H__
#define __GE_INPUT_H__
#include <stdint.h>
struct ge_input;
typedef struct ge_input ge_input_t;
typedef union ge_input_event {
void* ctx;
uintptr_t num;
} ge_input_event_t;
typedef int(*ge_input_send_func_t)(ge_input_t* ctx, ge_input_event_t event);
typedef int(*ge_input_peek_func_t)(ge_input_t* ctx, ge_input_event_t* event);
typedef int(*ge_input_recv_func_t)(ge_input_t* ctx, ge_input_event_t* event);
struct ge_input {
void* context;
ge_input_send_func_t func_send;
ge_input_peek_func_t func_peek;
ge_input_recv_func_t func_recv;
};
#endif // __GE_INPUT_H__

View File

@ -0,0 +1,236 @@
/*
* A generic kernel FIFO implementation
*
* Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net>
*
* 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
* (at your option) any later version.
*
* This program 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __GE_KFIFO_H__
#define __GE_KFIFO_H__
/**
* 仿照linux内核中的kfifo实现
*/
#ifndef GE_MEMORY_BARRIR
#define GE_MEMORY_BARRIR() __sync_synchronize()
#endif
#ifndef GE_ARRAY_SIZE
#define GE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
struct __ge_kfifo {
unsigned int in;
unsigned int out;
unsigned int mask;
unsigned int esize;
void *data;
};
#define __STRUCT_GE_KFIFO(type, size) \
{ \
struct __ge_kfifo kfifo; \
type buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
}
/**
* DECLARE_KFIFO - macro to declare a fifo object
* @fifo: name of the declared fifo
* @type: type of the fifo elements
* @size: the number of elements in the fifo, this must be a power of 2
*/
#define DECLARE_GE_KFIFO(fifo, type, size, tname) struct tname __STRUCT_GE_KFIFO(type, size) fifo
#define INIT_GE_KFIFO(fifo) do { \
struct __ge_kfifo *__kfifo = &((fifo)->kfifo); \
__kfifo->in = 0; \
__kfifo->out = 0; \
__kfifo->mask = GE_ARRAY_SIZE((fifo)->buf) - 1; \
__kfifo->esize = sizeof(*((fifo)->buf)); \
__kfifo->data = (fifo)->buf; \
} while (0)
/**
* DEFINE_KFIFO - macro to define and initialize a fifo
* @fifo: name of the declared fifo datatype
* @type: type of the fifo elements
* @size: the number of elements in the fifo, this must be a power of 2
*
* Note: the macro can be used for global and local fifo data type variables.
*/
#define DEFINE_GE_KFIFO(fifo, type, size, tname) \
DECLARE_GE_KFIFO(fifo, type, size, tname) = \
(struct tname) { { \
.in = 0, \
.out = 0, \
.mask = GE_ARRAY_SIZE((fifo).buf) - 1, \
.esize = sizeof(*(fifo).buf), \
.data = (fifo).buf, \
}, { 0 } }
/**
* kfifo_size - returns the size of the fifo in elements
* @fifo: address of the fifo to be used
*/
#define ge_kfifo_size(fifo) \
((fifo)->kfifo.mask + 1)
/**
* kfifo_len - returns the number of used elements in the fifo
* @fifo: address of the fifo to be used
*/
#define ge_kfifo_len(fifo) \
((fifo)->kfifo.in - (fifo)->kfifo.out)
/**
* kfifo_is_empty - returns true if the fifo is empty
* @fifo: address of the fifo to be used
*/
#define ge_kfifo_is_empty(fifo) \
((fifo)->kfifo.in == (fifo)->kfifo.out)
/**
* kfifo_is_full - returns true if the fifo is full
* @fifo: address of the fifo to be used
*/
#define ge_kfifo_is_full(fifo) (ge_kfifo_len(fifo) > (fifo)->kfifo.mask)
/**
* kfifo_put - put data into the fifo
* @fifo: address of the fifo to be used
* @val: the data to be added
*
* This macro copies the given value into the fifo.
* It returns 0 if the fifo was full. Otherwise it returns the number
* processed elements.
*
* Note that with only one concurrent reader and one concurrent
* writer, you don't need extra locking to use these macro.
*/
#define ge_kfifo_put(fifo, val) do { \
unsigned int __ret; \
struct __ge_kfifo *__kfifo = &((fifo)->kfifo); \
__ret = !ge_kfifo_is_full(fifo); \
if (__ret) { \
((fifo)->buf)[__kfifo->in & __kfifo->mask] = val; \
/*smp_wmb();*/ \
GE_MEMORY_BARRIR(); \
__kfifo->in++; \
} \
/*__ret;*/ \
} while(0)
/**
* kfifo_get - get data from the fifo
* @fifo: address of the fifo to be used
* @val: address where to store the data
*
* This macro reads the data from the fifo.
* It returns 0 if the fifo was empty. Otherwise it returns the number
* processed elements.
*
* Note that with only one concurrent reader and one concurrent
* writer, you don't need extra locking to use these macro.
*/
#define ge_kfifo_get(fifo, val) do { \
unsigned int __ret; \
struct __ge_kfifo *__kfifo = &((fifo)->kfifo); \
__ret = !ge_kfifo_is_empty(fifo); \
if (__ret) { \
*val = ((fifo)->buf)[__kfifo->out & __kfifo->mask]; \
/*smp_wmb();*/ \
GE_MEMORY_BARRIR(); \
__kfifo->out++; \
} \
/*__ret;*/ \
} while(0)
/**
* kfifo_peek - get data from the fifo without removing
* @fifo: address of the fifo to be used
* @val: address where to store the data
*
* This reads the data from the fifo without removing it from the fifo.
* It returns 0 if the fifo was empty. Otherwise it returns the number
* processed elements.
*
* Note that with only one concurrent reader and one concurrent
* writer, you don't need extra locking to use these macro.
*/
#define ge_kfifo_peek(fifo, val) do { \
unsigned int __ret; \
struct __ge_kfifo *__kfifo = &((fifo)->kfifo); \
__ret = !ge_kfifo_is_empty(fifo); \
if (__ret) { \
*val = ((fifo)->buf)[__kfifo->out & __kfifo->mask]; \
/*smp_wmb();*/ \
GE_MEMORY_BARRIR(); \
} \
/*__ret;*/ \
} while(0)
/**
* kfifo_in - put data into the fifo
* @fifo: address of the fifo to be used
* @buf: the data to be added
* @n: number of elements to be added
*
* This macro copies the given buffer into the fifo and returns the
* number of copied elements.
*
* Note that with only one concurrent reader and one concurrent
* writer, you don't need extra locking to use these macro.
*/
/*
#define kfifo_in(fifo, buf, n) \
({ \
typeof((fifo) + 1) __tmp = (fifo); \
typeof(__tmp->ptr_const) __buf = (buf); \
unsigned long __n = (n); \
const size_t __recsize = sizeof(*__tmp->rectype); \
struct __kfifo *__kfifo = &__tmp->kfifo; \
(__recsize) ?\
__kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
__kfifo_in(__kfifo, __buf, __n); \
})
*/
/**
* kfifo_out - get data from the fifo
* @fifo: address of the fifo to be used
* @buf: pointer to the storage buffer
* @n: max. number of elements to get
*
* This macro gets some data from the fifo and returns the numbers of elements
* copied.
*
* Note that with only one concurrent reader and one concurrent
* writer, you don't need extra locking to use these macro.
*/
/*
#define kfifo_out(fifo, buf, n) \
({ \
typeof((fifo) + 1) __tmp = (fifo); \
typeof(__tmp->ptr) __buf = (buf); \
unsigned long __n = (n); \
const size_t __recsize = sizeof(*__tmp->rectype); \
struct __kfifo *__kfifo = &__tmp->kfifo; \
(__recsize) ?\
__kfifo_out_r(__kfifo, __buf, __n, __recsize) : \
__kfifo_out(__kfifo, __buf, __n); \
})
*/
#endif // __GE_KFIFO_H__

View File

@ -0,0 +1,42 @@
#ifndef __GE_RENDER_H__
#define __GE_RENDER_H__
#include "ge_resource.h"
typedef int ge_render_unit_t;
typedef int ge_render_color_t;
typedef struct ge_render_pos2 {
ge_render_unit_t x;
ge_render_unit_t y;
} ge_render_pos2_t;
typedef struct ge_render_rect {
ge_render_pos2_t pos;
ge_render_pos2_t size;
} ge_render_rect_t;
struct ge_render;
typedef struct ge_render ge_render_t;
typedef int(*ge_render_init_func_t) (ge_render_t* ctx, const ge_render_pos2_t* init_screen_size);
typedef int(*ge_render_flush_func_t) (ge_render_t* ctx);
typedef int(*ge_render_draw_point_func_t) (ge_render_t* ctx, const ge_render_pos2_t* pos, ge_render_color_t color);
typedef int(*ge_render_draw_rect_func_t) (ge_render_t* ctx, const ge_render_rect_t* rect, ge_render_color_t color);
typedef int(*ge_render_draw_text_func_t) (ge_render_t* ctx, const ge_render_pos2_t* pos, const char* text);
typedef int(*ge_render_draw_resource_func_t)(ge_render_t* ctx, const ge_render_pos2_t* pos, const ge_resource_t* res);
struct ge_render {
void* context;
const ge_render_pos2_t screen_size;
ge_render_init_func_t init_func;
ge_render_flush_func_t func_flush;
ge_render_draw_point_func_t func_draw_point;
ge_render_draw_rect_func_t func_draw_rect;
ge_render_draw_text_func_t func_draw_text;
ge_render_draw_resource_func_t func_draw_res;
};
#endif // __GE_RENDER_H__

View File

@ -0,0 +1,12 @@
#ifndef __GE_RESOURCE_H__
#define __GE_RESOURCE_H__
struct ge_resource;
typedef struct ge_resource ge_resource_t;
struct ge_resource {
int type;
void* context;
};
#endif // __GE_RESOURCE_H__

View File

@ -0,0 +1,23 @@
#ifndef __GE_TIMER_H__
#define __GE_TIMER_H__
#include <stdint.h>
typedef uint64_t ge_time_t;
struct ge_timer;
typedef struct ge_timer ge_timer_t;
typedef void(*ge_timer_getus_func_t)(ge_timer_t* timer);
typedef void(*ge_timer_sleepus_func_t)(const ge_timer_t* timer);
typedef void(*ge_timer_getms_func_t)(ge_timer_t* timer);
typedef void(*ge_timer_sleepms_func_t)(const ge_timer_t* timer);
struct ge_timer {
ge_time_t time;
ge_timer_getms_func_t func_getms;
ge_timer_sleepms_func_t func_sleepms;
ge_timer_getus_func_t func_getus;
ge_timer_sleepus_func_t func_sleepus;
};
#endif // __GE_TIMER_H__