Sfoglia il codice sorgente

Fix common files for mbed

core
tmk 10 anni fa
parent
commit
412ca57be1

+ 5
- 5
common.mk Vedi File

@@ -7,18 +7,18 @@ SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/action_layer.c \
$(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/keymap.c \
$(COMMON_DIR)/avr/timer.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/bootloader.c \
$(COMMON_DIR)/suspend.c \
$(COMMON_DIR)/util.c \
$(COMMON_DIR)/avr/suspend.c \
$(COMMON_DIR)/avr/xprintf.S \
$(COMMON_DIR)/util.c
$(COMMON_DIR)/avr/timer.c \
$(COMMON_DIR)/avr/bootloader.c


# Option modules
ifdef BOOTMAGIC_ENABLE
SRC += $(COMMON_DIR)/bootmagic.c
SRC += $(COMMON_DIR)/eeconfig.c
SRC += $(COMMON_DIR)/avr/eeconfig.c
OPT_DEFS += -DBOOTMAGIC_ENABLE
endif


common/bootloader.c → common/avr/bootloader.c Vedi File


common/eeconfig.c → common/avr/eeconfig.c Vedi File


common/suspend.c → common/avr/suspend.c Vedi File

@@ -1,7 +1,29 @@
#include "suspend.h"
#include <stdbool.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include "matrix.h"
#include "action.h"
#include "backlight.h"
#include "suspend_avr.h"
#include "suspend.h"


#define wdt_intr_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
"r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
_BV(WDIE) | (value & 0x07)) ) \
: "r0" \
)


void suspend_power_down(void)

+ 27
- 0
common/avr/suspend_avr.h Vedi File

@@ -0,0 +1,27 @@
#ifndef SUSPEND_AVR_H
#define SUSPEND_AVR_H

#include <stdint.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>


#define wdt_intr_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
"r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
_BV(WDIE) | (value & 0x07)) ) \
: "r0" \
)

#endif

+ 2
- 2
common/host.h Vedi File

@@ -32,8 +32,8 @@ extern "C" {
extern bool keyboard_nkro;
#endif

uint8_t keyboard_idle;
uint8_t keyboard_protocol;
extern uint8_t keyboard_idle;
extern uint8_t keyboard_protocol;


/* host driver */

+ 0
- 1
common/keyboard.c Vedi File

@@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <util/delay.h>
#include "keyboard.h"
#include "matrix.h"
#include "keymap.h"

+ 0
- 1
common/keymap.c Vedi File

@@ -14,7 +14,6 @@ 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, see <http://www.gnu.org/licenses/>.
*/
#include <avr/pgmspace.h>
#include "keymap.h"
#include "report.h"
#include "keycode.h"

+ 4
- 0
common/mbed/bootloader.c Vedi File

@@ -0,0 +1,4 @@
#include "bootloader.h"


void bootloader_jump(void) {}

+ 6
- 0
common/mbed/suspend.c Vedi File

@@ -0,0 +1,6 @@
#include <stdbool.h>


void suspend_power_down(void) {}
bool suspend_wakeup_condition(void) { return true; }
void suspend_wakeup_init(void) {}

+ 46
- 0
common/mbed/xprintf.cpp Vedi File

@@ -0,0 +1,46 @@
#include <cstdarg>
//#include <stdarg.h>
#include "mbed.h"
#include "mbed/xprintf.h"


#define STRING_STACK_LIMIT 120

/* mbed Serial */
Serial ser(UART_TX, UART_RX);

/* TODO: Need small implementation for embedded */
int xprintf(const char* format, ...)
{
/* copy from mbed/common/RawSerial.cpp */
std::va_list arg;
va_start(arg, format);
int len = vsnprintf(NULL, 0, format, arg);
if (len < STRING_STACK_LIMIT) {
char temp[STRING_STACK_LIMIT];
vsprintf(temp, format, arg);
ser.puts(temp);
} else {
char *temp = new char[len + 1];
vsprintf(temp, format, arg);
ser.puts(temp);
delete[] temp;
}
va_end(arg);
return len;

/* Fail: __builtin_va_arg_pack?
* https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
void *arg = __builtin_apply_args();
void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
__builtin_return(ret)
*/
/* Fail: varargs can not be passed to printf
//int r = ser.printf("test %i\r\n", 123);
va_list arg;
va_start(arg, format);
int r = ser.printf(format, arg);
va_end(arg);
return r;
*/
}

+ 17
- 0
common/mbed/xprintf.h Vedi File

@@ -0,0 +1,17 @@
#ifndef XPRINTF_H
#define XPRINTF_H

//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)

#ifdef __cplusplus
extern "C" {
#endif

int xprintf(const char *format, ...);

#ifdef __cplusplus
}
#endif


#endif

+ 0
- 1
common/mousekey.c Vedi File

@@ -16,7 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <util/delay.h>
#include "keycode.h"
#include "host.h"
#include "timer.h"

+ 14
- 6
common/mousekey.h Vedi File

@@ -52,12 +52,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif


uint8_t mk_delay;
uint8_t mk_interval;
uint8_t mk_max_speed;
uint8_t mk_time_to_max;
uint8_t mk_wheel_max_speed;
uint8_t mk_wheel_time_to_max;
#ifdef __cplusplus
extern "C" {
#endif

extern uint8_t mk_delay;
extern uint8_t mk_interval;
extern uint8_t mk_max_speed;
extern uint8_t mk_time_to_max;
extern uint8_t mk_wheel_max_speed;
extern uint8_t mk_wheel_time_to_max;


void mousekey_task(void);
@@ -66,4 +70,8 @@ void mousekey_off(uint8_t code);
void mousekey_clear(void);
void mousekey_send(void);

#ifdef __cplusplus
}
#endif

#endif

+ 11
- 0
common/progmem.h Vedi File

@@ -0,0 +1,11 @@
#ifndef PROGMEM_H
#define PROGMEM_H 1

#if defined(__AVR__)
# include <avr/pgmspace.h>
#elif defined(__arm__)
# define PROGMEM
# define pgm_read_byte(p) *(p)
#endif

#endif

+ 0
- 20
common/suspend.h Vedi File

@@ -3,26 +3,6 @@

#include <stdint.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>


#define wdt_intr_enable(value) \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %0,%1" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
"sts %0,%2" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
"r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
_BV(WDIE) | (value & 0x07)) ) \
: "r0" \
)


void suspend_power_down(void);