From: AceVest Date: Sun, 17 Jun 2018 08:32:58 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/README?a=commitdiff_plain;h=4de8c6c3a46f7222edb3e71e7972a6b1eb70fa41;p=acecode.git ... --- diff --git a/arduino/hardware/ace/avr/cores/avr/AceAvr.h b/arduino/hardware/ace/avr/cores/avr/AceAvr.h index 9e48440..38fb062 100644 --- a/arduino/hardware/ace/avr/cores/avr/AceAvr.h +++ b/arduino/hardware/ace/avr/cores/avr/AceAvr.h @@ -9,13 +9,30 @@ #pragma once +#include +#include + +#define LOW 0 +#define HIGH 1 + +#define INPUT 0 +#define OUTPUT 1 +#define INPUT_PULLUP 2 + +void delay(unsigned long ms); +void acevest(); + // ATmega328P #define __SFR_OFFSET 0x20 #define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr)) #define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET) -#define SREG _SFR_IO8(0x3F) -#define DDRB _SFR_IO8(0x04) -#define PORTB _SFR_IO8(0x05) +#define DDRB _SFR_IO8(0x04) +#define PORTB _SFR_IO8(0x05) +#define DDRC _SFR_IO8(0x07) +#define PORTC _SFR_IO8(0x08) +#define DDRD _SFR_IO8(0x0A) +#define PORTD _SFR_IO8(0x0B) +#define SREG _SFR_IO8(0x3F) // F_CPU 定义在命令行中 #ifndef F_CPU @@ -26,3 +43,19 @@ #define cli() __asm__ __volatile__ ("cli" ::: "memory") #define sei() __asm__ __volatile__ ("sei" ::: "memory") #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) + + +const uint8_t PA = 1; +const uint8_t PB = 2; +const uint8_t PC = 3; +const uint8_t PD = 4; + + +uint8_t get_digital_pin_port(uint8_t pin); +uint8_t get_digital_pin_bit_mask(uint8_t pin); +volatile uint8_t* get_digital_pin_port_mode_register(uint8_t pin); +volatile uint8_t* get_digital_pin_port_output_register(uint8_t pin); + + +void set_digital_pin_mode(uint8_t pin, uint8_t mode); +void digital_write(uint8_t pin, uint8_t val); diff --git a/arduino/hardware/ace/avr/cores/avr/Arduino.h b/arduino/hardware/ace/avr/cores/avr/Arduino.h index df4d362..f90c621 100644 --- a/arduino/hardware/ace/avr/cores/avr/Arduino.h +++ b/arduino/hardware/ace/avr/cores/avr/Arduino.h @@ -9,9 +9,5 @@ #pragma once -#include -#include #include -void delay(unsigned long ms); -void acevest(); diff --git a/arduino/hardware/ace/avr/cores/avr/a.sh b/arduino/hardware/ace/avr/cores/avr/a.sh new file mode 100755 index 0000000..1b4c2d8 --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/a.sh @@ -0,0 +1,2 @@ +avr-gcc -g -O0 -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10804 -DARDUINO_ACE_AVR -DARDUINO_ARCH_AVR "-I/Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr" "-I/Users/ace/workspace/Arduino/hardware/ace/avr/variants/avr" "/Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/main.cpp" -o "main" +avr-gcc -c -g -O0 -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10804 -DARDUINO_ACE_AVR -DARDUINO_ARCH_AVR "-I/Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr" "-I/Users/ace/workspace/Arduino/hardware/ace/avr/variants/avr" "/Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/main.cpp" -o "main.cpp.o" diff --git a/arduino/hardware/ace/avr/cores/avr/avr.cpp b/arduino/hardware/ace/avr/cores/avr/avr.cpp new file mode 100644 index 0000000..f61ed70 --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/avr.cpp @@ -0,0 +1,83 @@ +#include + +// On the board, digital pins are also used +// for the analog output (software PWM). Analog input +// pins are a separate set. + +// ATMEL ATMEGA328P +// +// +-\/-+ +// PC6 1| |28 PC5 (AI 5) (D 19) +// (D 0) PD0 2| |27 PC4 (AI 4) (D 18) +// (D 1) PD1 3| |26 PC3 (AI 3) (D 17) +// (D 2) PD2 4| |25 PC2 (AI 2) (D 16) +// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) (D 15) +// (D 4) PD4 6| |23 PC0 (AI 0) (D 14) +// VCC 7| |22 GND +// GND 8| |21 AREF +// PB6 9| |20 AVCC +// PB7 10| |19 PB5 (D 13) +// PWM+ (D 5) PD5 11| |18 PB4 (D 12) +// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM +// (D 7) PD7 13| |16 PB2 (D 10) PWM +// (D 8) PB0 14| |15 PB1 (D 9) PWM +// +----+ +// +// (PWM+ indicates the additional PWM pins on the ATmega168.) + +uint8_t get_digital_pin_port(uint8_t pin) { + if(pin < 8) { + return PD; + } + + if(pin < 14) { + return PB; + } + + return PC; +} + +uint8_t get_digital_pin_bit_mask(uint8_t pin) { + uint8_t seg = 0; + + switch(get_digital_pin_port(pin)) { + case PB: + seg = 8; + break; + case PC: + seg = 14; + break; + case PD: + seg = 0; + break; + } + + return (1 << (pin - seg)); +} + +volatile uint8_t* get_digital_pin_port_mode_register(uint8_t pin) { + switch(get_digital_pin_port(pin)) { + case PB: + return &DDRB; + case PC: + return &DDRC; + case PD: + return &DDRD; + } + + return 0; +} + + +volatile uint8_t* get_digital_pin_port_output_register(uint8_t pin) { + switch(get_digital_pin_port(pin)) { + case PB: + return &PORTB; + case PC: + return &PORTC; + case PD: + return &PORTC; + } + + return 0; +} diff --git a/arduino/hardware/ace/avr/cores/avr/backup/code1 b/arduino/hardware/ace/avr/cores/avr/backup/code1 new file mode 100644 index 0000000..fbfd546 --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/backup/code1 @@ -0,0 +1,82 @@ +/* + * ------------------------------------------------------------------------ + * File Name: main.cpp + * Author: Zhao Yanbai + * 2018-06-14 20:21:33 Thursday CST + * Description: none + * ------------------------------------------------------------------------ + */ +#include + + +#if 0 +volatile unsigned long timer0_overflow_count = 0; + +//extern "C" void TIMER0_OVF_vect() __attribute__ ((signal,used, externally_visible)); +//void TIMER0_OVF_vect() + +extern "C" void __vector_16() __attribute__ ((signal,used, externally_visible)); +void __vector_16() +{ + timer0_overflow_count++; +} + + + +int main() { +__asm__ __volatile__ ("sei" ::: "memory"); +__asm__ __volatile__ ("nop" ::: "memory"); +__asm__ __volatile__ ("nop" ::: "memory"); + uint8_t oldSREG = SREG; + oldSREG = 0xAA; + SREG = oldSREG; + uint16_t x = (uint16_t)(&DDRB); + x++; +__asm__ __volatile__ ("nop" ::: "memory"); +__asm__ __volatile__ ("nop" ::: "memory"); +__asm__ __volatile__ ("cli" ::: "memory"); + + return 0; +} +#else + +void init_timer0(); + +void init() { + sei(); + init_timer0(); +} + +int main() +{ + init(); + + //uint8_t pin = 13; + uint8_t bit = 1<<4; // pin 13是 B组的第5个 + volatile uint8_t *reg = ((volatile uint8_t *)((uint16_t)(&DDRB))); + volatile uint8_t *out = ((volatile uint8_t *)((uint16_t)(&PORTB))); + + // set pin output + uint8_t oldSREG = SREG; + cli(); + *reg |= bit; + SREG = oldSREG; + + const int d = 1000; + int n = 0; + + while(1) { + n++; + + oldSREG = SREG; + cli(); + /* HIGH */ /* LOW */ + n % 2 == 0 ? *out |= bit : *out &= ~bit; + SREG = oldSREG; + + delay(d); + } + + return 0; +} +#endif diff --git a/arduino/hardware/ace/avr/cores/avr/lib.cpp b/arduino/hardware/ace/avr/cores/avr/lib.cpp new file mode 100644 index 0000000..c2bd8dc --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/lib.cpp @@ -0,0 +1,46 @@ +/* + * ------------------------------------------------------------------------ + * File Name: lib.cpp + * Author: Zhao Yanbai + * 2018-06-17 15:27:28 Sunday CST + * Description: none + * ------------------------------------------------------------------------ + */ +#include + +void set_digital_pin_mode(uint8_t pin, uint8_t mode) { + uint8_t bit_mask = get_digital_pin_bit_mask(pin); + volatile uint8_t *mod_reg = get_digital_pin_port_mode_register(pin); + volatile uint8_t *out_reg = get_digital_pin_port_output_register(pin); + + if(0 == mod_reg || 0 == out_reg) return; + + uint8_t oldSREG = SREG; + cli(); + + switch(mode) { + case INPUT: + *mod_reg &= ~bit_mask; + *out_reg &= ~bit_mask; + break; + case INPUT_PULLUP: + *mod_reg &= ~bit_mask; + *out_reg |= ~bit_mask; + break; + case OUTPUT: + *mod_reg |= bit_mask; + break; + } + + SREG = oldSREG; +} + +void digital_write(uint8_t pin, uint8_t val) { + uint8_t bit_mask = get_digital_pin_bit_mask(pin); + volatile uint8_t *out_reg = get_digital_pin_port_output_register(pin); + + uint8_t oldSREG = SREG; + cli(); + val == LOW ? *out_reg &= ~bit_mask : *out_reg |= bit_mask; + SREG = oldSREG; +} diff --git a/arduino/hardware/ace/avr/cores/avr/main b/arduino/hardware/ace/avr/cores/avr/main new file mode 100755 index 0000000..0327266 Binary files /dev/null and b/arduino/hardware/ace/avr/cores/avr/main differ diff --git a/arduino/hardware/ace/avr/cores/avr/main.cpp b/arduino/hardware/ace/avr/cores/avr/main.cpp index d402d78..6892650 100644 --- a/arduino/hardware/ace/avr/cores/avr/main.cpp +++ b/arduino/hardware/ace/avr/cores/avr/main.cpp @@ -6,44 +6,37 @@ * Description: none * ------------------------------------------------------------------------ */ -#include - +#include void init_timer0(); +void init_timer1(); void init() { sei(); init_timer0(); + init_timer1(); } +extern uint8_t tick; int main() { init(); - //uint8_t pin = 13; - uint8_t bit = 1<<5; // pin 13是 B组的第5个 - volatile uint8_t *reg = ((volatile uint8_t *)((uint16_t)(&DDRB))); - volatile uint8_t *out = ((volatile uint8_t *)((uint16_t)(&PORTB))); + uint8_t pin = 12; + set_digital_pin_mode(pin, OUTPUT); - // set pin output - uint8_t oldSREG = SREG; - cli(); - *reg |= bit; - SREG = oldSREG; - - const int d = 1000; int n = 0; - + uint8_t state = LOW; while(1) { n++; - oldSREG = SREG; - cli(); - /* HIGH */ /* LOW */ - n % 2 == 0 ? *out |= bit : *out &= ~bit; - SREG = oldSREG; + if(tick > 100) { + state = state == LOW ? HIGH : LOW; + tick = 0; + } - delay(d); + digital_write(pin, state); + delay(10); } return 0; diff --git a/arduino/hardware/ace/avr/cores/avr/main.cpp.d b/arduino/hardware/ace/avr/cores/avr/main.cpp.d new file mode 100644 index 0000000..ded7b7e --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/main.cpp.d @@ -0,0 +1,4 @@ +main.cpp.o: \ + /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/main.cpp \ + /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/Arduino.h \ + /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/AceAvr.h diff --git a/arduino/hardware/ace/avr/cores/avr/main.d b/arduino/hardware/ace/avr/cores/avr/main.d new file mode 100644 index 0000000..cade3be --- /dev/null +++ b/arduino/hardware/ace/avr/cores/avr/main.d @@ -0,0 +1,3 @@ +main: /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/main.cpp \ + /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/Arduino.h \ + /Users/ace/workspace/Arduino/hardware/ace/avr/cores/avr/AceAvr.h diff --git a/arduino/hardware/ace/avr/cores/avr/timer.cpp b/arduino/hardware/ace/avr/cores/avr/timer.cpp index f88e153..9a3092c 100644 --- a/arduino/hardware/ace/avr/cores/avr/timer.cpp +++ b/arduino/hardware/ace/avr/cores/avr/timer.cpp @@ -9,13 +9,8 @@ #include -extern "C" void TIMER0_OVF_vect() __attribute__ ((signal,used, externally_visible)); -volatile unsigned long timer0_overflow_count = 0; -void TIMER0_OVF_vect() -{ - timer0_overflow_count++; -} +volatile unsigned long timer0_overflow_count = 0; #if 0 static void __empty() { // Empty @@ -69,3 +64,35 @@ void init_timer0() { // enable timer 0 overflow interrupt sbi(TIMSK0, TOIE0); } + + + + +void init_timer1() { + //set timer1 interrupt at 100Hz + TCCR1A = 0;// set entire TCCR1A register to 0 + TCCR1B = 0;// same for TCCR1B + TCNT1 = 0;//initialize counter value to 0 + // set compare match register for 100Hz increments + OCR1A = 155; // = (16*10^6) / (1024*100Hz) - 1 (must be <65536) + // turn on CTC mode + TCCR1B |= (1 << WGM12); + // Set CS10 and CS12 bits for 1024 prescaler + TCCR1B |= (1 << CS12) | (1 << CS10); + // enable timer compare interrupt + TIMSK1 |= (1 << OCIE1A); +} + +extern "C" void TIMER0_OVF_vect() __attribute__ ((signal,used, externally_visible)); +void TIMER0_OVF_vect() +{ + timer0_overflow_count++; +} + + +extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal,used, externally_visible)); +uint8_t tick = 0; +void TIMER1_COMPA_vect() +{ + tick++; +} diff --git a/documents/ATmega328P.md b/documents/ATmega328P.md new file mode 100644 index 0000000..1ff4eef --- /dev/null +++ b/documents/ATmega328P.md @@ -0,0 +1,67 @@ +# ATmega328P + + +## 中断 +### 中断向量表 +|Vector| No Program Address| Source Interrupts| definition| +|:-:|---|---|:--| +|0| 0x0000| RESET| External Pin, Power-on Reset, Brown-out Reset and Watchdog System Reset| +|1| 0x0002| INT0| External Interrupt Request 0| +|2| 0x0004| INT1| External Interrupt Request 1| +|3| 0x0006| PCINT0| Pin Change Interrupt Request 0| +|4| 0x0008| PCINT1| Pin Change Interrupt Request 1| +|5| 0x000A| PCINT2| Pin Change Interrupt Request 2| +|6| 0x000C| WDT| Watchdog Time-out Interrupt| +|7| 0x000E| TIMER2_COMPA| Timer/Counter2 Compare Match A| +|8| 0x0010| TIMER2_COMPB| Timer/Coutner2 Compare Match B| +|9| 0x0012| TIMER2_OVF| Timer/Counter2 Overflow| +|10| 0x0014| TIMER1_CAPT| Timer/Counter1 Capture Event| +|11| 0x0016| TIMER1_COMPA| Timer/Counter1 Compare Match A| +|12| 0x0018| TIMER1_COMPB| Timer/Coutner1 Compare Match B| +|13| 0x001A| TIMER1_OVF| Timer/Counter1 Overflow| +|14| 0x001C| TIMER0_COMPA| Timer/Counter0 Compare Match A| +|15| 0x001E| TIMER0_COMPB| Timer/Coutner0 Compare Match B| +|16| 0x0020| TIMER0_OVF| Timer/Counter0 Overflow| +|17| 0x0022| SPI STC| SPI Serial Transfer Complete| +|18| 0x0024| USART_RX| USART Rx Complete| +|19| 0x0026| USART_UDRE| USART Data Register Empty| +|20| 0x0028| USART_TX| USART Tx Complete| +|21| 0x002A| ADC| ADC Conversion Complete| +|22| 0x002C| EE READY| EEPROM Ready| +|23| 0x002E| ANALOG COMP| Analog Comparator| +|24| 0x0030| TWI| 2-wire Serial Interface (I2C)| +|25| 0x0032| SPM| READY Store Program Memory Ready| + +上表中的地址是按16bit算的 + +编写对应的中断程序,以`TIMER1_OVF`举例,按如下格式 + +``` +extern "C" void __vector_16() __attribute__ ((signal,used, externally_visible)); +void __vector_16() +{ + // ... +} +``` + +### 中断向量表所在位置 +|BOOTRST| IVSEL| Reset Address| Interrupt Vectors Start Address| +|---|---|---|:--| +|1| 0| 0x000| 0x002| +|1| 1| 0x000| Boot Reset Address + 0x0002| +|0| 0| Boot Reset Address| 0x002| +|0| 1| Boot Reset Address| Boot Reset Address + 0x0002| + +* BOOTRST是fuse.high_byte.BOOTRST比特们,1表示unprogramed,reset时从地址0开始,0表示programed,reset时从地址`Boot Reset Address`开始 +* 地址`Boot Reset Address`与BOOTSZ即fuse.hih_byte[2:1]相关 +* IVSEL是MCUCR寄存器的第1个bit + +### 外部中断 +* 如果启用中断,就算将INT、PCINT引脚配置成`OUTPUT`也会触发中断 +### PCINT和INT引脚的差别 +* INT限制在了两个端口上面,而PCINT则是所有接口都具备。 +* INT具有上沿,下沿,低电平,高电平触发这几种模式,而PCINT只有测量电平的变化这一个模式。 +* INT可以了解具体是哪个口触发的,而PCINT不行。 +* PCINT不会直接跳转入指定的程序,用户需要读取寄存器来做判断是哪个PCINT端口产生了变化。 +* INT0和INT1各自可配置一个中断程序入口,而所有的PCINT都只会触发跳转进入一条指定的程序。 + diff --git a/learn/doc/mac_bash_profile b/learn/doc/mac_bash_profile index 295697b..a6103c2 100644 --- a/learn/doc/mac_bash_profile +++ b/learn/doc/mac_bash_profile @@ -5,9 +5,11 @@ HISTCONTROL=ignoreboth #export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" export PATH=/usr/local/sbin:$PATH export PATH=/Users/Ace/.local/bin:$PATH +export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin export GOBIN=/Users/Ace/.local/bin -export PATH=/Users/Ace/workspace/github/metasploit-framework:$PATH -export MSF_DATABASE_CONFIG=/Users/Ace/workspace/github/metasploit-framework/config/database.yml +export IDF_PATH=$HOME/esp/esp-idf +export PATH=$PATH:/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/ +export PATH=$PATH:$HOME/Library/Arduino15/packages/arduino/tools/avrdude/6.0.1-arduino5/bin #多个GOPATH用';'分隔 go get会存到第一个目录 export GOPATH=/Users/Ace/go export PS1="\W\$ " diff --git a/learn/doc/vimrc b/learn/doc/vimrc index cf110be..72f9f27 100644 --- a/learn/doc/vimrc +++ b/learn/doc/vimrc @@ -99,6 +99,8 @@ autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set ai autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set sw=4 autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set ts=4 autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set sts=4 +autocmd FileType php,python,h,c,java,perl,shell,bash,vim,ruby,cc,cpp set expandtab + "golang默认使用TAB "autocmd FileType go set ai diff --git a/tools/hzk16/HZK16C b/tools/hzk16/HZK16C new file mode 100755 index 0000000..65b02a9 Binary files /dev/null and b/tools/hzk16/HZK16C differ diff --git a/tools/hzk16/HZK16X b/tools/hzk16/HZK16X new file mode 100755 index 0000000..68144b0 Binary files /dev/null and b/tools/hzk16/HZK16X differ diff --git a/tools/hzk16/hz_16x16_c_code_maker.py b/tools/hzk16/hz_16x16_c_code_maker.py new file mode 100755 index 0000000..165e05e --- /dev/null +++ b/tools/hzk16/hz_16x16_c_code_maker.py @@ -0,0 +1,137 @@ +#!/usr/bin/python +#encoding: utf-8 +import sys +import binascii + +RECT_HEIGHT = 16 +RECT_WIDTH = 16 +BYTE_COUNT_PER_ROW = RECT_WIDTH / 8 +BYTE_COUNT_PER_FONT = BYTE_COUNT_PER_ROW * RECT_HEIGHT + +KEYS = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01] + +class FontRender(object): + def __init__(self, font_file, + rect_height=RECT_HEIGHT, rect_width=RECT_WIDTH, byte_count_per_row=BYTE_COUNT_PER_ROW): + self.font_file = font_file + self.rect_height = rect_height + self.rect_width = rect_width + self.byte_count_per_row = byte_count_per_row + + self.__init_rect_list__() + + self.c_code_list = [] + + def __init_rect_list__(self): + self.rect_list = [] * RECT_HEIGHT + + for i in range(RECT_HEIGHT): + self.rect_list.append([] * RECT_WIDTH) + + def get_font_area_index(self, txt, encoding='utf-8'): + if not isinstance(txt, unicode): + txt = txt.decode(encoding) + + gb2312 = txt.encode('gb2312') + hex_str = binascii.b2a_hex(gb2312) + + area = eval('0x' + hex_str[:2]) - 0xA0 + index = eval('0x' + hex_str[2:]) - 0xA0 + + return area, index + + def get_font_rect(self, area, index): + offset = (94 * (area-1) + (index-1)) * BYTE_COUNT_PER_FONT + btxt = None + + with open(self.font_file, "rb") as f: + f.seek(offset) + btxt = f.read(BYTE_COUNT_PER_FONT) + + return btxt + + def convert_font_rect(self, font_rect): + for k in range(len(font_rect) / self.byte_count_per_row): + row_list = self.rect_list[k] + for j in range(self.byte_count_per_row): + for i in range(8): + asc = binascii.b2a_hex(font_rect[k * self.byte_count_per_row + j]) + asc = eval('0x' + asc) + flag = asc & KEYS[i] + row_list.append(flag) + + def make_c_code(self, font_rect, ch) : + c_code_str = '\n // {0}\n'.format(ch) + c_code_str += ' {' + for k in range(len(font_rect) / self.byte_count_per_row): + row_list = self.rect_list[k] + for j in range(self.byte_count_per_row): + data = 0 + for i in range(8): + asc = binascii.b2a_hex(font_rect[k * self.byte_count_per_row + j]) + asc = eval('0x' + asc) + flag = asc & KEYS[i] + data <<= 1 + if flag != 0 : + data |= 1 + + if k != 0 or j != 0 : + c_code_str= c_code_str + ',' + c_code_str= c_code_str + str(hex(data)) + + + c_code_str += '}' + self.c_code_list.append(c_code_str) + + + + def render_font_rect(self, rect_list=None): + if not rect_list: + rect_list = self.rect_list + + for row in rect_list: + for i in row: + if i: + print '■', + else: + print '○', + print + + def print_c_code(self) : + s = 'const uint8_t PROGMEM chinese_str[][{0}] = '.format(BYTE_COUNT_PER_FONT) + s += '{' + for i in range(0, len(self.c_code_list)) : + if i != 0 : + s += ',' + s += self.c_code_list[i] + + s += '\n};' + + print(s) + + + def convert(self, text, encoding='utf-8'): + if not isinstance(text, unicode): + text = text.decode(encoding) + + for t in text: + area, index = self.get_font_area_index(t) + font_rect = self.get_font_rect(area, index) + + self.make_c_code(font_rect, t.encode(encoding)) + self.convert_font_rect(font_rect) + + def get_rect_info(self): + return self.rect_list + +if '__main__' == __name__: + text = u'' + if len(sys.argv) != 2 : + print("Usage:\n {0} ".format(sys.argv[0])) + text = sys.argv[1] + fr = FontRender('./hzk16s') + fr.convert(text) + # print fr.get_rect_info() + # fr.render_font_rect() + fr.print_c_code() + diff --git a/tools/hzk16/hzk16f b/tools/hzk16/hzk16f new file mode 100755 index 0000000..eff886f Binary files /dev/null and b/tools/hzk16/hzk16f differ diff --git a/tools/hzk16/hzk16h b/tools/hzk16/hzk16h new file mode 100755 index 0000000..fd430f8 Binary files /dev/null and b/tools/hzk16/hzk16h differ diff --git a/tools/hzk16/hzk16k b/tools/hzk16/hzk16k new file mode 100755 index 0000000..d509911 Binary files /dev/null and b/tools/hzk16/hzk16k differ diff --git a/tools/hzk16/hzk16l b/tools/hzk16/hzk16l new file mode 100755 index 0000000..be8cf18 Binary files /dev/null and b/tools/hzk16/hzk16l differ diff --git a/tools/hzk16/hzk16s b/tools/hzk16/hzk16s new file mode 100755 index 0000000..410af8a Binary files /dev/null and b/tools/hzk16/hzk16s differ diff --git a/tools/hzk16/hzk16v b/tools/hzk16/hzk16v new file mode 100755 index 0000000..47ef6bb Binary files /dev/null and b/tools/hzk16/hzk16v differ diff --git a/tools/hzk16/hzk16y b/tools/hzk16/hzk16y new file mode 100755 index 0000000..723f878 Binary files /dev/null and b/tools/hzk16/hzk16y differ diff --git a/tools/hzk16/readme.txt b/tools/hzk16/readme.txt new file mode 100644 index 0000000..aee5b7b --- /dev/null +++ b/tools/hzk16/readme.txt @@ -0,0 +1,22 @@ +hzk16所有字体 下面是在WINDOWS下面生成的不同字体风格的HZK16: +宋  --HZK16S +仿  --HZK16F +黑  --HZK16H +楷  --HZK16K 仿与楷字型相近而风格仍有差别 +幼圆 --HZK16Y +隶  --HZK16L 效果较差 + +另三个是DOS下汉字系统的字库: +粗  --HZK16C +细  --HZK16X 类XZL字体 +繁  --HZK16V + +附件1中是宋仿黑楷幼圆5种字库 附件2中是粗细繁隶4种 ">hzk16所有字体 下面是在WINDOWS下面生成的不同字体风格的HZK16: +宋  --HZK16S +仿  --HZK16F +黑  --HZK16H +楷  --HZK16K 仿与楷字型相近而风格仍有差别 +幼圆 --HZK16Y +隶  --HZK16L 效果较差 + +另三个是DOS下汉字 [更多]