mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-13 18:58:49 +01:00
Merge pull request #20 from clockworkpi/develop
Develop devterm-printer now with cjk freetype
This commit is contained in:
commit
e9d66e78ac
@ -8,35 +8,35 @@
|
|||||||
|
|
||||||
int bcmToGpioCPi[64] =
|
int bcmToGpioCPi[64] =
|
||||||
{
|
{
|
||||||
106, 107, // 0, 1
|
58, 57, // 0, 1
|
||||||
104, 10, // 2, 3
|
167, 0, // 2, 3
|
||||||
3, 9, // 4 5
|
1, 2, // 4 5
|
||||||
4, 90, // 6, 7
|
3, 4, // 6, 7
|
||||||
92, 158, // 8, 9
|
5, 6, // 8, 9
|
||||||
156, 105, //10,11
|
7, 8, //10,11
|
||||||
146, 150, //12,13
|
15, 54, //12,13
|
||||||
81, 80, //14,15
|
134, 135, //14,15
|
||||||
|
|
||||||
82, 83, //16,17
|
137, 136, //16,17
|
||||||
131, 132, //18,19
|
139, 138, //18,19
|
||||||
134, 135, //20,21
|
141, 140, //20,21
|
||||||
89, 88, //22,23
|
128, 129, //22,23
|
||||||
84, 85, //24,25
|
130, 131, //24,25
|
||||||
86, 87, //26,27
|
132, 133, //26,27
|
||||||
112, 113, //28,29
|
9, 201, //28,29
|
||||||
109, 157, //30,31
|
196, 199, //30,31
|
||||||
|
|
||||||
148, 147, //32,33
|
161, 160, //32,33
|
||||||
100, 101, //34,35
|
227, 198, //34,35
|
||||||
102, 103, //36,37
|
163, 166, //36,37
|
||||||
97, 98, //38,39
|
165, 164, //38,39
|
||||||
99, 96, //40,41
|
228, 224, //40,41
|
||||||
110, 111, //42,43
|
225, 226, //42,43
|
||||||
64, 65, //44,45
|
56, 55, //44,45
|
||||||
-1, -1, //46,47
|
-1, -1, //46,47
|
||||||
|
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63
|
||||||
}
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -81,32 +81,60 @@ static char *alts [] =
|
|||||||
"IN", "OUT", "ALT2", "ALT3", "ALT4", "ALT5", "ALT6", "OFF"
|
"IN", "OUT", "ALT2", "ALT3", "ALT4", "ALT5", "ALT6", "OFF"
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
static char* get_pin_name(int pin)
|
||||||
|
{
|
||||||
|
static char name[10];
|
||||||
|
char c;
|
||||||
|
int b, d;
|
||||||
|
|
||||||
|
b = pin/32;
|
||||||
|
d = pin % 32;
|
||||||
|
|
||||||
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
|
|
||||||
|
if(b < 6)
|
||||||
|
c = b + 'C';
|
||||||
|
else
|
||||||
|
c = b - 6 + 'L';
|
||||||
|
sprintf(name, "P%c%d", c, d);
|
||||||
|
|
||||||
|
#elif defined(CONFIG_CLOCKWORKPI_A06)
|
||||||
|
|
||||||
|
c = d/8 + 'A';
|
||||||
|
sprintf(name, "%d%c%d", b, c, d % 8);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
void CPiReadAll(void)
|
void CPiReadAll(void)
|
||||||
{
|
{
|
||||||
int pin, pin2;
|
int pin, pin2;
|
||||||
int tmp = wiringPiDebug;
|
int tmp = wiringPiDebug;
|
||||||
wiringPiDebug = FALSE;
|
wiringPiDebug = FALSE;
|
||||||
|
|
||||||
printf (" +-----+------+------+---+-----+------+------+---+\n");
|
printf (" +-----+------+------+------+---+-----+------+------+------+---+\n");
|
||||||
printf (" | BCM | GPIO | Mode | V | BCM | GPIO | Mode | V |\n");
|
printf (" | BCM | GPIO | Name | Mode | V | BCM | GPIO | Name | Mode | V |\n");
|
||||||
printf (" +-----+------+------+---+-----+------+------+---+\n");
|
printf (" +-----+------+------+------+---+-----+------+------+------+---+\n");
|
||||||
|
|
||||||
for (pin = 0 ; pin < 23; pin ++) {
|
for (pin = 0 ; pin < 23; pin ++) {
|
||||||
printf (" | %3d", pin);
|
printf (" | %3d", pin);
|
||||||
printf (" | %4d", bcmToGpioCPi[pin]);
|
printf (" | %4d", bcmToGpioCPi[pin]);
|
||||||
|
printf (" | %-4s", get_pin_name(bcmToGpioCPi[pin]));
|
||||||
printf (" | %4s", alts [CPi_get_gpio_mode(bcmToGpioCPi[pin])]);
|
printf (" | %4s", alts [CPi_get_gpio_mode(bcmToGpioCPi[pin])]);
|
||||||
printf (" | %d", CPi_digitalRead(bcmToGpioCPi[pin])) ;
|
printf (" | %d", CPi_digitalRead(bcmToGpioCPi[pin])) ;
|
||||||
pin2 = pin + 23;
|
pin2 = pin + 23;
|
||||||
printf (" | %3d", pin2);
|
printf (" | %3d", pin2);
|
||||||
printf (" | %4d", bcmToGpioCPi[pin2]);
|
printf (" | %4d", bcmToGpioCPi[pin2]);
|
||||||
|
printf (" | %-4s", get_pin_name(bcmToGpioCPi[pin2]));
|
||||||
printf (" | %4s", alts [CPi_get_gpio_mode(bcmToGpioCPi[pin2])]);
|
printf (" | %4s", alts [CPi_get_gpio_mode(bcmToGpioCPi[pin2])]);
|
||||||
printf (" | %d", CPi_digitalRead(bcmToGpioCPi[pin2])) ;
|
printf (" | %d", CPi_digitalRead(bcmToGpioCPi[pin2])) ;
|
||||||
printf (" |\n") ;
|
printf (" |\n") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf (" +-----+------+------+---+-----+------+------+---+\n");
|
printf (" +-----+------+------+------+---+-----+------+------+------+---+\n");
|
||||||
printf (" | BCM | GPIO | Mode | V | BCM | GPIO | Mode | V |\n");
|
printf (" | BCM | GPIO | Name | Mode | V | BCM | GPIO | Name | Mode | V |\n");
|
||||||
printf (" +-----+------+------+---+-----+------+------+---+\n");
|
printf (" +-----+------+------+------+---+-----+------+------+------+---+\n");
|
||||||
|
|
||||||
wiringPiDebug = tmp;
|
wiringPiDebug = tmp;
|
||||||
}
|
}
|
||||||
@ -117,6 +145,38 @@ void CPiReadAllRaw(void)
|
|||||||
int tmp = wiringPiDebug;
|
int tmp = wiringPiDebug;
|
||||||
wiringPiDebug = FALSE;
|
wiringPiDebug = FALSE;
|
||||||
|
|
||||||
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
|
|
||||||
|
printf (" +------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+\n");
|
||||||
|
printf (" | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V |\n");
|
||||||
|
printf (" +------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+\n");
|
||||||
|
|
||||||
|
for (pin = 0 ; pin < 27; pin++) {
|
||||||
|
pin2 = pin;
|
||||||
|
for(i = 0; i < 6; i++) {
|
||||||
|
if(CPi_get_gpio_mode(pin2) >= 0) {
|
||||||
|
printf (" | %4d", pin2) ;
|
||||||
|
printf (" | %-4s", get_pin_name(pin2));
|
||||||
|
printf (" | %4s", alts [CPi_get_gpio_mode(pin2)]) ;
|
||||||
|
printf (" | %d", CPi_digitalRead(pin2)) ;
|
||||||
|
} else {
|
||||||
|
printf (" | ") ;
|
||||||
|
printf (" | ") ;
|
||||||
|
printf (" | ") ;
|
||||||
|
printf (" | ") ;
|
||||||
|
}
|
||||||
|
pin2 += 32;
|
||||||
|
if(i == 1) pin2 += 64;
|
||||||
|
}
|
||||||
|
printf (" |\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (" +------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+\n");
|
||||||
|
printf (" | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V | GPIO | Name | Mode | V |\n");
|
||||||
|
printf (" +------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+------+------+------+---+\n");
|
||||||
|
|
||||||
|
#elif defined(CONFIG_CLOCKWORKPI_A06)
|
||||||
|
|
||||||
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
||||||
printf (" | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V |\n");
|
printf (" | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V |\n");
|
||||||
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
||||||
@ -136,6 +196,8 @@ void CPiReadAllRaw(void)
|
|||||||
printf (" | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V |\n");
|
printf (" | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V | GPIO | Mode | V |\n");
|
||||||
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
printf (" +------+------+---+------+------+---+------+------+---+------+------+---+------+------+---+\n");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
wiringPiDebug = tmp;
|
wiringPiDebug = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,22 +30,53 @@ static int wpimode = -1 ;
|
|||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A04
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
|
|
||||||
int CPI_PIN_MASK[12][32] = //[BANK] [INDEX]
|
int bcmToGpioCPi[64] =
|
||||||
{
|
{
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PA
|
58, 57, // 0, 1
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PB
|
167, 0, // 2, 3
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PC
|
1, 2, // 4 5
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,15,16,-1,18,-1,-1,21,22,23,24,25,26,-1,-1,-1,-1,-1,},//PD
|
3, 4, // 6, 7
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PE
|
5, 6, // 8, 9
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PF
|
7, 8, //10,11
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PG
|
15, 54, //12,13
|
||||||
{-1,-1,-1, 3, 4, 5, 6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PH
|
134, 135, //14,15
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PI
|
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PJ
|
137, 136, //16,17
|
||||||
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PK
|
139, 138, //18,19
|
||||||
{-1,-1, 2, 3,-1,-1,-1,-1, 8,-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PL
|
141, 140, //20,21
|
||||||
|
128, 129, //22,23
|
||||||
|
130, 131, //24,25
|
||||||
|
132, 133, //26,27
|
||||||
|
9, 201, //28,29
|
||||||
|
196, 199, //30,31
|
||||||
|
|
||||||
|
161, 160, //32,33
|
||||||
|
227, 198, //34,35
|
||||||
|
163, 166, //36,37
|
||||||
|
165, 164, //38,39
|
||||||
|
228, 224, //40,41
|
||||||
|
225, 226, //42,43
|
||||||
|
56, 55, //44,45
|
||||||
|
-1, -1, //46,47
|
||||||
|
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int CPI_PIN_MASK[8][32] = //[BANK] [INDEX]
|
||||||
|
{
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,},//PC 0
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1,},//PD 32
|
||||||
|
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PE 64
|
||||||
|
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PF 96
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,},//PG 128
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,},//PH 160
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,},//PL 192
|
||||||
|
{ 1, 1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PM 224
|
||||||
|
};
|
||||||
|
|
||||||
|
volatile uint32_t *gpio_base;
|
||||||
|
volatile uint32_t *gpioL_base;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
@ -84,11 +115,11 @@ int bcmToGpioCPi[64] =
|
|||||||
|
|
||||||
int CPI_PIN_MASK[5][32] = //[BANK] [INDEX]
|
int CPI_PIN_MASK[5][32] = //[BANK] [INDEX]
|
||||||
{
|
{
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PA
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//GPIO0
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PB
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//GPIO1
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PC
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//GPIO2
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PD
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//GPIO3
|
||||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PD
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//GPIO4
|
||||||
};
|
};
|
||||||
|
|
||||||
volatile uint32_t *cru_base;
|
volatile uint32_t *cru_base;
|
||||||
@ -132,8 +163,17 @@ static unsigned int readR(unsigned int addr)
|
|||||||
return val;
|
return val;
|
||||||
|
|
||||||
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
||||||
|
|
||||||
uint32_t val = 0;
|
uint32_t val = 0;
|
||||||
|
uint32_t mmap_base = (addr & ~MAP_MASK);
|
||||||
|
uint32_t mmap_seek = ((addr - mmap_base) >> 2);
|
||||||
|
|
||||||
|
if (addr >= GPIOL_BASE)
|
||||||
|
val = *(gpioL_base + mmap_seek);
|
||||||
|
else
|
||||||
|
val = *(gpio_base + mmap_seek);
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +205,14 @@ static void writeR(unsigned int val, unsigned int addr)
|
|||||||
|
|
||||||
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
||||||
|
|
||||||
|
unsigned int mmap_base = (addr & ~MAP_MASK);
|
||||||
|
unsigned int mmap_seek = ((addr - mmap_base) >> 2);
|
||||||
|
|
||||||
|
if (addr >= GPIOL_BASE)
|
||||||
|
*(gpioL_base + mmap_seek) = val;
|
||||||
|
else
|
||||||
|
*(gpio_base + mmap_seek) = val;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,6 +224,9 @@ int CPi_get_gpio_mode(int pin)
|
|||||||
unsigned int phyaddr = 0;
|
unsigned int phyaddr = 0;
|
||||||
unsigned char mode = -1;
|
unsigned char mode = -1;
|
||||||
|
|
||||||
|
if (CPI_PIN_MASK[bank][index] < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
|
|
||||||
unsigned int grf_phyaddr = 0, ddr_phyaddr = 0;
|
unsigned int grf_phyaddr = 0, ddr_phyaddr = 0;
|
||||||
@ -202,31 +253,29 @@ int CPi_get_gpio_mode(int pin)
|
|||||||
ddr_phyaddr = GPIO4_BASE + GPIO_SWPORTA_DDR_OFFSET;
|
ddr_phyaddr = GPIO4_BASE + GPIO_SWPORTA_DDR_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CPI_PIN_MASK[bank][index] != -1) {
|
|
||||||
regval = readR(grf_phyaddr);
|
regval = readR(grf_phyaddr);
|
||||||
mode = (regval >> (offset << 1)) & 0x3;
|
mode = (regval >> (offset << 1)) & 0x3;
|
||||||
|
|
||||||
if(mode == 0){
|
if(mode == 0){
|
||||||
regval = readR(ddr_phyaddr);
|
regval = readR(ddr_phyaddr);
|
||||||
return (regval >> index) & 1;
|
return (regval >> index) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mode + 1;
|
return mode + 1;
|
||||||
}
|
|
||||||
|
|
||||||
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
||||||
|
|
||||||
int offset = ((index - ((index >> 3) << 3)) << 2);
|
int offset = ((index - ((index >> 3) << 3)) << 2);
|
||||||
|
|
||||||
if (bank == 11) {
|
if (bank >= 6) {
|
||||||
phyaddr = GPIOL_BASE + ((index >> 3) << 2);
|
phyaddr = GPIOL_BASE + (bank -6) * 0x24 + ((index >> 3) << 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
phyaddr = GPIO_BASE_MAP + (bank * 0x24) + ((index >> 3) << 2);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
phyaddr = GPIO_BASE_MAP + (bank * 36) + ((index >> 3) << 2);
|
|
||||||
|
|
||||||
/* Ignore unused gpio */
|
|
||||||
if (CPI_PIN_MASK[bank][index] != -1) {
|
|
||||||
regval = readR(phyaddr);
|
regval = readR(phyaddr);
|
||||||
mode = (regval >> offset) & 7;
|
mode = (regval >> offset) & 7;
|
||||||
}
|
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
|
|
||||||
@ -243,21 +292,23 @@ int CPi_set_gpio_mode(int pin, int mode)
|
|||||||
unsigned int index = pin - (bank << 5);
|
unsigned int index = pin - (bank << 5);
|
||||||
unsigned int phyaddr = 0;
|
unsigned int phyaddr = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
int offset = ((index - ((index >> 3) << 3)));
|
|
||||||
unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr;
|
|
||||||
#elif (defined CONFIG_CLOCKWORKPI_A04)
|
|
||||||
int offset = ((index - ((index >> 3) << 3)) << 2);
|
int offset = ((index - ((index >> 3) << 3)) << 2);
|
||||||
|
|
||||||
if (bank == 11) {
|
if (bank >= 6) {
|
||||||
phyaddr = GPIOL_BASE + ((index >> 3) << 2);
|
phyaddr = GPIOL_BASE + (bank -6) * 0x24 + ((index >> 3) << 2);
|
||||||
} else {
|
} else {
|
||||||
phyaddr = GPIO_BASE_MAP + (bank * 36) + ((index >> 3) << 2);
|
phyaddr = GPIO_BASE_MAP + (bank * 0x24) + ((index >> 3) << 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
|
|
||||||
|
int offset = ((index - ((index >> 3) << 3)));
|
||||||
|
unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr;
|
||||||
|
|
||||||
if(bank == 0){
|
if(bank == 0){
|
||||||
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET;
|
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET;
|
||||||
grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2);
|
grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2);
|
||||||
@ -295,7 +346,6 @@ int CPi_set_gpio_mode(int pin, int mode)
|
|||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("Register[%#x]: %#x index:%d\n", phyaddr, regval, index);
|
printf("Register[%#x]: %#x index:%d\n", phyaddr, regval, index);
|
||||||
|
|
||||||
/* Set Input */
|
|
||||||
if (INPUT == mode) {
|
if (INPUT == mode) {
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
writeR(0xffff0180, cru_phyaddr);
|
writeR(0xffff0180, cru_phyaddr);
|
||||||
@ -317,7 +367,7 @@ int CPi_set_gpio_mode(int pin, int mode)
|
|||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("Input mode set over reg val: %#x\n",regval);
|
printf("Input mode set over reg val: %#x\n",regval);
|
||||||
#endif
|
#endif
|
||||||
} else if (OUTPUT == mode) { /* Set Output */
|
} else if (OUTPUT == mode) {
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
writeR(0xffff0180, cru_phyaddr);
|
writeR(0xffff0180, cru_phyaddr);
|
||||||
regval = readR(grf_phyaddr);
|
regval = readR(grf_phyaddr);
|
||||||
@ -341,7 +391,7 @@ int CPi_set_gpio_mode(int pin, int mode)
|
|||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("Out mode get value: 0x%x\n",regval);
|
printf("Out mode get value: 0x%x\n",regval);
|
||||||
#endif
|
#endif
|
||||||
}else
|
} else
|
||||||
printf("Unknow mode\n");
|
printf("Unknow mode\n");
|
||||||
} else
|
} else
|
||||||
printf("unused pin\n");
|
printf("unused pin\n");
|
||||||
@ -356,10 +406,10 @@ int CPi_set_gpio_alt(int pin, int mode)
|
|||||||
unsigned int phyaddr = 0;
|
unsigned int phyaddr = 0;
|
||||||
int offset = ((index - ((index >> 3) << 3)) << 2);
|
int offset = ((index - ((index >> 3) << 3)) << 2);
|
||||||
|
|
||||||
if (bank == 11) {
|
if (bank >= 6) {
|
||||||
phyaddr = GPIOL_BASE + ((index >> 3) << 2);
|
phyaddr = GPIOL_BASE + ((index >> 3) << 2);
|
||||||
}else
|
}else
|
||||||
phyaddr = GPIO_BASE_MAP + (bank * 36) + ((index >> 3) << 2);
|
phyaddr = GPIO_BASE_MAP + (bank * 0x24) + ((index >> 3) << 2);
|
||||||
|
|
||||||
/* Ignore unused gpio */
|
/* Ignore unused gpio */
|
||||||
if (CPI_PIN_MASK[bank][index] != -1) {
|
if (CPI_PIN_MASK[bank][index] != -1) {
|
||||||
@ -385,22 +435,22 @@ void CPi_digitalWrite(int pin, int value)
|
|||||||
unsigned int bank = pin >> 5;
|
unsigned int bank = pin >> 5;
|
||||||
unsigned int index = pin - (bank << 5);
|
unsigned int index = pin - (bank << 5);
|
||||||
unsigned int phyaddr = 0;
|
unsigned int phyaddr = 0;
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
|
||||||
unsigned int regval = 0;
|
|
||||||
unsigned int cru_phyaddr = 0;
|
|
||||||
|
|
||||||
#else
|
|
||||||
unsigned int regval = 0;
|
unsigned int regval = 0;
|
||||||
|
|
||||||
if (bank == 11) {
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
phyaddr = GPIOL_BASE + 0x10;
|
|
||||||
|
if (bank >= 6) {
|
||||||
|
phyaddr = GPIOL_BASE + (bank -6) * 0x24 + 0x10;
|
||||||
|
} else {
|
||||||
|
phyaddr = GPIO_BASE_MAP + (bank * 0x24) + 0x10;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
phyaddr = GPIO_BASE_MAP + (bank * 36) + 0x10;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
|
|
||||||
|
unsigned int cru_phyaddr = 0;
|
||||||
|
|
||||||
if(bank == 0){
|
if(bank == 0){
|
||||||
phyaddr = GPIO0_BASE + GPIO_SWPORTA_DR_OFFSET;
|
phyaddr = GPIO0_BASE + GPIO_SWPORTA_DR_OFFSET;
|
||||||
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET;
|
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET;
|
||||||
@ -426,9 +476,9 @@ void CPi_digitalWrite(int pin, int value)
|
|||||||
|
|
||||||
if (CPI_PIN_MASK[bank][index] != -1) {
|
if (CPI_PIN_MASK[bank][index] != -1) {
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
writeR(0xffff0180, cru_phyaddr);
|
writeR(0xffff0180, cru_phyaddr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("pin: %d, bank: %d, index: %d, phyaddr: 0x%x\n", pin, bank, index, phyaddr);
|
printf("pin: %d, bank: %d, index: %d, phyaddr: 0x%x\n", pin, bank, index, phyaddr);
|
||||||
@ -450,9 +500,7 @@ void CPi_digitalWrite(int pin, int value)
|
|||||||
printf("HIGH val set over reg val: 0x%x\n", regval);
|
printf("HIGH val set over reg val: 0x%x\n", regval);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
}
|
||||||
printf("unused pin\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -463,19 +511,20 @@ int CPi_digitalRead(int pin)
|
|||||||
int bank = pin >> 5;
|
int bank = pin >> 5;
|
||||||
int index = pin - (bank << 5);
|
int index = pin - (bank << 5);
|
||||||
int val;
|
int val;
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A04
|
|
||||||
|
|
||||||
unsigned int phyaddr;
|
unsigned int phyaddr;
|
||||||
|
|
||||||
if (bank == 11) {
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
phyaddr = GPIOL_BASE + 0x10;
|
|
||||||
|
if (bank >= 6) {
|
||||||
|
phyaddr = GPIOL_BASE + (bank -6) * 0x24 + 0x10;
|
||||||
} else {
|
} else {
|
||||||
phyaddr = GPIO_BASE_MAP + (bank * 36) + 0x10;
|
phyaddr = GPIO_BASE_MAP + (bank * 0x24) + 0x10;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
unsigned int phyaddr;
|
|
||||||
if(bank == 0)
|
if(bank == 0)
|
||||||
phyaddr = GPIO0_BASE + GPIO_EXT_PORTA_OFFSET;
|
phyaddr = GPIO0_BASE + GPIO_EXT_PORTA_OFFSET;
|
||||||
else if(bank == 1)
|
else if(bank == 1)
|
||||||
@ -486,6 +535,7 @@ int CPi_digitalRead(int pin)
|
|||||||
phyaddr = GPIO3_BASE + GPIO_EXT_PORTA_OFFSET;
|
phyaddr = GPIO3_BASE + GPIO_EXT_PORTA_OFFSET;
|
||||||
else if(bank == 4)
|
else if(bank == 4)
|
||||||
phyaddr = GPIO4_BASE + GPIO_EXT_PORTA_OFFSET;
|
phyaddr = GPIO4_BASE + GPIO_EXT_PORTA_OFFSET;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (CPI_PIN_MASK[bank][index] != -1) {
|
if (CPI_PIN_MASK[bank][index] != -1) {
|
||||||
@ -493,7 +543,7 @@ int CPi_digitalRead(int pin)
|
|||||||
val = val >> index;
|
val = val >> index;
|
||||||
val &= 1;
|
val &= 1;
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("Read reg val: 0x%#x, bank:%d, index:%d\n", val, bank, index);
|
printf("Read reg val: 0x%#x, bank:%d, index:%d phyaddr: 0x%x\n", val, bank, index, phyaddr);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -504,9 +554,15 @@ int CPiSetup(int fd)
|
|||||||
{
|
{
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A04
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
|
|
||||||
|
gpio_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIOA_BASE);
|
||||||
|
if ((int32_t)(unsigned long)gpio_base == -1)
|
||||||
|
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
|
||||||
|
gpioL_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIOL_BASE);
|
||||||
|
if ((int32_t)(unsigned long)gpioL_base == -1)
|
||||||
|
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
|
||||||
|
|
||||||
#elif defined(CONFIG_CLOCKWORKPI_A06)
|
#elif defined(CONFIG_CLOCKWORKPI_A06)
|
||||||
|
|
||||||
gpio0_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO0_BASE);
|
gpio0_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO0_BASE);
|
||||||
if ((int32_t)(unsigned long)gpio0_base == -1)
|
if ((int32_t)(unsigned long)gpio0_base == -1)
|
||||||
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO0_BASE) failed: %s\n", strerror(errno));
|
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO0_BASE) failed: %s\n", strerror(errno));
|
||||||
@ -535,6 +591,7 @@ int CPiSetup(int fd)
|
|||||||
pmugrf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUGRF_BASE);
|
pmugrf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUGRF_BASE);
|
||||||
if ((int32_t)(unsigned long)pmugrf_base == -1)
|
if ((int32_t)(unsigned long)pmugrf_base == -1)
|
||||||
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (PMUGRF_BASE) failed: %s\n", strerror(errno));
|
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (PMUGRF_BASE) failed: %s\n", strerror(errno));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
wpimode = WPI_MODE_BCM;
|
wpimode = WPI_MODE_BCM;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,14 +2,11 @@
|
|||||||
#define _WIRING_CPI_H
|
#define _WIRING_CPI_H
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A04
|
#ifdef CONFIG_CLOCKWORKPI_A04
|
||||||
#define GPIOA_BASE (0x0300B000)
|
#define GPIOA_BASE 0x0300B000
|
||||||
#define GPIO_NUM (0x40)
|
#define GPIO_BASE_MAP (GPIOA_BASE + 0x24 * 2)
|
||||||
#define GPIO_BASE_MAP (0x0300B000)
|
|
||||||
#define MEM_INFO (1024)
|
|
||||||
#define GPIOL_BASE (0x07022000)
|
#define GPIOL_BASE (0x07022000)
|
||||||
#define GPIOL_BASE_MAP (0x07022000)
|
|
||||||
#define MAP_SIZE_L (4096 * 1)
|
|
||||||
#define GPIO_PWM_OP (0x0300A000)
|
#define GPIO_PWM_OP (0x0300A000)
|
||||||
|
#define GPIO_NUM (256)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI_A06
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
@ -18,7 +15,6 @@
|
|||||||
#define GPIO2_BASE 0xff780000
|
#define GPIO2_BASE 0xff780000
|
||||||
#define GPIO3_BASE 0xff788000
|
#define GPIO3_BASE 0xff788000
|
||||||
#define GPIO4_BASE 0xff790000
|
#define GPIO4_BASE 0xff790000
|
||||||
#define GPIO_NUM (160)
|
|
||||||
#define GPIO_SWPORTA_DR_OFFSET 0x00
|
#define GPIO_SWPORTA_DR_OFFSET 0x00
|
||||||
#define GPIO_SWPORTA_DDR_OFFSET 0x04
|
#define GPIO_SWPORTA_DDR_OFFSET 0x04
|
||||||
#define GPIO_EXT_PORTA_OFFSET 0x50
|
#define GPIO_EXT_PORTA_OFFSET 0x50
|
||||||
@ -26,12 +22,12 @@
|
|||||||
#define GRF_BASE 0xff77e000
|
#define GRF_BASE 0xff77e000
|
||||||
#define CRU_BASE 0xff760000
|
#define CRU_BASE 0xff760000
|
||||||
#define PMUCRU_BASE 0xff750000
|
#define PMUCRU_BASE 0xff750000
|
||||||
#define CRU_CLKGATE_CON31_OFFSET 0x037c //bit 3 4 5
|
#define CRU_CLKGATE_CON31_OFFSET 0x037c
|
||||||
#define PMUCRU_CLKGATE_CON1_OFFSET 0x0104
|
#define PMUCRU_CLKGATE_CON1_OFFSET 0x0104
|
||||||
|
#define GPIO_NUM (160)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAP_SIZE_L (4*1024)
|
#define MAP_SIZE (4*1024)
|
||||||
#define MAP_SIZE MAP_SIZE_L
|
|
||||||
#define MAP_MASK (MAP_SIZE - 1)
|
#define MAP_MASK (MAP_SIZE - 1)
|
||||||
|
|
||||||
extern int CPi_set_gpio_mode(int pin, int mode);
|
extern int CPi_set_gpio_mode(int pin, int mode);
|
||||||
|
|||||||
@ -109,7 +109,7 @@ int wiringPiSPISetupMode (int channel, int speed, int mode)
|
|||||||
// Channel can be anything - lets hope for the best
|
// Channel can be anything - lets hope for the best
|
||||||
// channel &= 1 ; // Channel is 0 or 1
|
// channel &= 1 ; // Channel is 0 or 1
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKWORKPI
|
#ifdef CONFIG_CLOCKWORKPI_A06
|
||||||
snprintf (spiDev, 31, "/dev/spidev2.%d", channel) ;
|
snprintf (spiDev, 31, "/dev/spidev2.%d", channel) ;
|
||||||
#else
|
#else
|
||||||
snprintf (spiDev, 31, "/dev/spidev0.%d", channel) ;
|
snprintf (spiDev, 31, "/dev/spidev0.%d", channel) ;
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
#define DRCN_ANALOG_READ 9
|
#define DRCN_ANALOG_READ 9
|
||||||
|
|
||||||
|
|
||||||
struct drcNetComStruct
|
typedef struct drcNetComStruct
|
||||||
{
|
{
|
||||||
uint32_t pin ;
|
uint32_t pin ;
|
||||||
uint32_t cmd ;
|
uint32_t cmd ;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
CFLAGS = -g -Wall
|
CFLAGS = -O0 -g -Wall
|
||||||
LDFLAUS =
|
LDFLAGS =
|
||||||
INCLUDES =
|
INCLUDES = -I /usr/include/freetype2
|
||||||
LIBS = -lwiringPi -lm -lcrypt -lpthread -lrt
|
LIBS = -lwiringPi -lm -lcrypt -lpthread -lfreetype -lrt
|
||||||
|
|
||||||
MAIN = devterm_thermal_printer.elf
|
MAIN = devterm_thermal_printer.elf
|
||||||
|
|
||||||
SRCS = printer.c devterm_thermal_printer.c utils.c
|
SRCS = printer.c devterm_thermal_printer.c utils.c ftype.c utf8-utils.c
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
.PHONY: depend clean
|
.PHONY: depend clean
|
||||||
|
|||||||
BIN
Code/thermal_printer/NotoSansCJK-Regular.ttf
Normal file
BIN
Code/thermal_printer/NotoSansCJK-Regular.ttf
Normal file
Binary file not shown.
@ -1,7 +1,11 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
///raspberry pi CM3
|
// clang-format off
|
||||||
|
#include <freetype2/ft2build.h>
|
||||||
|
#include <freetype/freetype.h>
|
||||||
|
// clang-format on
|
||||||
|
/// raspberry pi CM3
|
||||||
|
|
||||||
#define BCM_GPIO_28 28
|
#define BCM_GPIO_28 28
|
||||||
#define BCM_GPIO_29 29
|
#define BCM_GPIO_29 29
|
||||||
@ -22,12 +26,13 @@
|
|||||||
#define BCM_GPIO_44 44
|
#define BCM_GPIO_44 44
|
||||||
#define BCM_GPIO_45 45
|
#define BCM_GPIO_45 45
|
||||||
|
|
||||||
//PA8-12 UART1
|
// PA8-12 UART1
|
||||||
//#define SPI1_NSS_PIN PA4 //SPI_1 Chip Select pin is PA4. //no use in DevTerm
|
//#define SPI1_NSS_PIN PA4 //SPI_1 Chip Select pin is PA4. //no use in
|
||||||
|
//DevTerm
|
||||||
|
|
||||||
#define VH_PIN BCM_GPIO_40 //ENABLE_VH required,PRT_EN
|
#define VH_PIN BCM_GPIO_40 // ENABLE_VH required,PRT_EN
|
||||||
|
|
||||||
#define LATCH_PIN BCM_GPIO_36 //18
|
#define LATCH_PIN BCM_GPIO_36 // 18
|
||||||
#define PEM_PIN BCM_GPIO_34 // 1 [PS,PAPER]
|
#define PEM_PIN BCM_GPIO_34 // 1 [PS,PAPER]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -35,13 +40,13 @@
|
|||||||
#define ENABLE_PEM digitalWrite(PEM_CTL_PIN,HIGH)
|
#define ENABLE_PEM digitalWrite(PEM_CTL_PIN,HIGH)
|
||||||
#define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW)
|
#define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW)
|
||||||
*/
|
*/
|
||||||
//DevTerm no VPS IO
|
// DevTerm no VPS IO
|
||||||
//#define PEM_CTL_PIN
|
//#define PEM_CTL_PIN
|
||||||
#define ENABLE_PEM
|
#define ENABLE_PEM
|
||||||
#define DISABLE_PEM
|
#define DISABLE_PEM
|
||||||
|
|
||||||
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
|
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
|
||||||
//enable SPI0 ALT0 in CM3 first
|
// enable SPI0 ALT0 in CM3 first
|
||||||
// in /boot/config.txt
|
// in /boot/config.txt
|
||||||
// dtparam=spi=on
|
// dtparam=spi=on
|
||||||
// dtoverlay=spi-gpio35-39
|
// dtoverlay=spi-gpio35-39
|
||||||
@ -50,39 +55,34 @@
|
|||||||
#define MOSI_PIN BCM_GPIO_38
|
#define MOSI_PIN BCM_GPIO_38
|
||||||
#define CLK_PIN BCM_GPIO_39
|
#define CLK_PIN BCM_GPIO_39
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@brief STB_NUMBER stand for STROBE NUMBER of lines, which means how many lines
|
*@brief STB_NUMBER stand for STROBE NUMBER of lines, which means how many lines
|
||||||
* are going to be activated
|
* are going to be activated
|
||||||
**/
|
**/
|
||||||
#define STB_NUMBER 1
|
#define STB_NUMBER 1
|
||||||
|
|
||||||
#define STB1_PIN BCM_GPIO_37//13
|
#define STB1_PIN BCM_GPIO_37 // 13
|
||||||
#define STB2_PIN STB1_PIN
|
#define STB2_PIN STB1_PIN
|
||||||
#define STB3_PIN STB1_PIN
|
#define STB3_PIN STB1_PIN
|
||||||
#define STB4_PIN STB1_PIN
|
#define STB4_PIN STB1_PIN
|
||||||
#define STB5_PIN STB1_PIN
|
#define STB5_PIN STB1_PIN
|
||||||
#define STB6_PIN STB1_PIN
|
#define STB6_PIN STB1_PIN
|
||||||
|
|
||||||
|
|
||||||
#define PH1_PIN BCM_GPIO_28
|
#define PH1_PIN BCM_GPIO_28
|
||||||
#define PH2_PIN BCM_GPIO_29
|
#define PH2_PIN BCM_GPIO_29
|
||||||
#define PH3_PIN BCM_GPIO_30
|
#define PH3_PIN BCM_GPIO_30
|
||||||
#define PH4_PIN BCM_GPIO_31
|
#define PH4_PIN BCM_GPIO_31
|
||||||
|
|
||||||
///0 1 3 2 mine
|
/// 0 1 3 2 mine
|
||||||
#define PA_PIN PH1_PIN //
|
#define PA_PIN PH1_PIN //
|
||||||
#define PNA_PIN PH2_PIN //
|
#define PNA_PIN PH2_PIN //
|
||||||
#define PB_PIN PH3_PIN //
|
#define PB_PIN PH3_PIN //
|
||||||
#define PNB_PIN PH4_PIN //
|
#define PNB_PIN PH4_PIN //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#define ENABLE1_PIN PA13
|
//#define ENABLE1_PIN PA13
|
||||||
//#define ENABLE2_PIN PA14
|
//#define ENABLE2_PIN PA14
|
||||||
|
|
||||||
#define THERMISTORPIN BCM_GPIO_35 //ADC,14
|
#define THERMISTORPIN BCM_GPIO_35 // ADC,14
|
||||||
|
|
||||||
|
|
||||||
#define MOTOR_ENABLE1
|
#define MOTOR_ENABLE1
|
||||||
#define MOTOR_ENABLE2
|
#define MOTOR_ENABLE2
|
||||||
@ -98,8 +98,7 @@
|
|||||||
|
|
||||||
#define ASK4PAPER digitalRead(PEM_PIN)
|
#define ASK4PAPER digitalRead(PEM_PIN)
|
||||||
|
|
||||||
|
#define ERROR_FEED_PITCH ((uint8_t)0x01)
|
||||||
#define ERROR_FEED_PITCH ((uint8_t) 0x01)
|
|
||||||
#define IS_PAPER 0x00
|
#define IS_PAPER 0x00
|
||||||
#define NO_PAPER 0x01
|
#define NO_PAPER 0x01
|
||||||
#define HOT_PRINTER 0x02
|
#define HOT_PRINTER 0x02
|
||||||
@ -134,9 +133,7 @@
|
|||||||
#define Fontrows ((uint8_t)24)
|
#define Fontrows ((uint8_t)24)
|
||||||
#define FontColums ((uint8_t)16)
|
#define FontColums ((uint8_t)16)
|
||||||
|
|
||||||
#define nextcharactercolum ((uint8_t)Fontrows/8) // = 3
|
#define nextcharactercolum ((uint8_t)Fontrows / 8) // = 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define ASCII_TAB '\t' // Horizontal tab
|
#define ASCII_TAB '\t' // Horizontal tab
|
||||||
#define ASCII_LF '\n' // Line feed,10
|
#define ASCII_LF '\n' // Line feed,10
|
||||||
@ -161,7 +158,6 @@
|
|||||||
|
|
||||||
#define BITS8 8
|
#define BITS8 8
|
||||||
|
|
||||||
|
|
||||||
#define MAX_DOTS 384
|
#define MAX_DOTS 384
|
||||||
#define PRINTER_BITS MAX_DOTS
|
#define PRINTER_BITS MAX_DOTS
|
||||||
#define MAXPIXELS 48
|
#define MAXPIXELS 48
|
||||||
@ -172,75 +168,81 @@
|
|||||||
#define MAXPIXELS 72
|
#define MAXPIXELS 72
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FONT_MODE_0 0 // Internal
|
||||||
|
#define FONT_MODE_1 1 // External
|
||||||
|
|
||||||
//extract bits
|
// extract bits
|
||||||
#define LAST(k,n) ((k) & ((1<<(n))-1))
|
#define LAST(k, n) ((k) & ((1 << (n)) - 1))
|
||||||
#define MID(k,m,n) LAST((k)>>(m),((n)-(m)))
|
#define MID(k, m, n) LAST((k) >> (m), ((n) - (m)))
|
||||||
|
|
||||||
|
typedef struct _Margin {
|
||||||
typedef struct _Margin{
|
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint8_t esgs;
|
uint8_t esgs;
|
||||||
}Margin;
|
} Margin;
|
||||||
|
|
||||||
|
|
||||||
typedef struct _FONT {
|
typedef struct _FONT {
|
||||||
|
|
||||||
uint8_t width;//in bits
|
uint8_t width; // in bits
|
||||||
uint8_t height;
|
uint8_t height;
|
||||||
|
uint8_t mode; // 0 internal pcf font array,1 external ttf font file
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
}FONT;
|
char *file;
|
||||||
|
} FONT;
|
||||||
|
|
||||||
typedef struct _ImageCache{
|
typedef struct _ImageCache {
|
||||||
|
|
||||||
uint16_t idx;
|
uint16_t idx;
|
||||||
uint16_t num;
|
uint16_t num;
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
uint8_t need_print:1;
|
uint8_t need_print : 1;
|
||||||
uint8_t revert_bits:1;//MSB OR LSB
|
uint8_t revert_bits : 1; // MSB OR LSB
|
||||||
uint8_t cache[IMAGE_MAX]; // 48x192bytes(384x192 pixels) ,max
|
uint8_t cache[IMAGE_MAX]; // 48x192bytes(384x192 pixels) ,max
|
||||||
|
|
||||||
}ImageCache;
|
} ImageCache;
|
||||||
|
|
||||||
typedef struct _CONFIG
|
typedef struct _CONFIG {
|
||||||
{
|
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t line_space;
|
uint8_t line_space;
|
||||||
uint8_t align;
|
uint8_t align;
|
||||||
uint8_t reverse; //reverse print
|
uint8_t reverse; // reverse print
|
||||||
uint8_t orient;
|
uint8_t orient;
|
||||||
uint8_t under_line;
|
uint8_t under_line;
|
||||||
uint8_t feed_pitch;
|
uint8_t feed_pitch;
|
||||||
uint8_t density:4; //0-f,300+density*46 HEAT_TIME
|
uint8_t density : 4; // 0-f,300+density*46 HEAT_TIME
|
||||||
|
|
||||||
uint16_t wordgap:10;//1023 max
|
uint16_t wordgap : 10; // 1023 max
|
||||||
uint8_t max_pts;// max pts in print_dots_8bit_split
|
uint8_t max_pts; // max pts in print_dots_8bit_split
|
||||||
uint8_t lock;
|
uint8_t lock;
|
||||||
|
int16_t degree; // char rotate 0,90,180,270, -90,-180,-270
|
||||||
|
|
||||||
Margin margin;
|
Margin margin;
|
||||||
FONT*font;
|
FONT *font;
|
||||||
ImageCache *img;
|
ImageCache *img;
|
||||||
FILE*fp;
|
FILE *fp;
|
||||||
|
|
||||||
int (*printf)(struct _CONFIG*, char*, ...);
|
FT_Face face;
|
||||||
|
FT_Library ft;
|
||||||
|
|
||||||
}CONFIG;
|
int (*printf)(struct _CONFIG *, char *, ...);
|
||||||
|
|
||||||
|
} CONFIG;
|
||||||
|
|
||||||
typedef struct _SerialCache{
|
typedef struct _SerialCache {
|
||||||
uint8_t idx;
|
uint8_t idx;
|
||||||
uint8_t data[77];//384/5
|
uint8_t utf8idx; // 0-4
|
||||||
}SerialCache;
|
// uint8_t data[77];//384/5, minium size font 5 pixel
|
||||||
|
uint32_t data[MAX_DOTS]; // uint32_t for utf8 characters
|
||||||
|
} SerialCache;
|
||||||
|
|
||||||
typedef struct _TimeRec{
|
typedef struct _TimeRec {
|
||||||
unsigned int time;
|
unsigned int time;
|
||||||
uint8_t last_status;
|
uint8_t last_status;
|
||||||
uint8_t check;
|
uint8_t check;
|
||||||
|
|
||||||
}TimeRec;
|
} TimeRec;
|
||||||
|
|
||||||
void PrintDots8bit(uint8_t *Array, uint8_t characters,uint8_t feed_num);
|
void PrintDots8bit(uint8_t *Array, uint8_t characters, uint8_t feed_num);
|
||||||
|
|
||||||
uint8_t invert_bit(uint8_t a);
|
uint8_t invert_bit(uint8_t a);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@ After=devterm-socat
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
EnvironmentFile=/usr/local/etc/devterm-printer
|
||||||
StandardOutput=file:/tmp/devterm_printer.log
|
StandardOutput=file:/tmp/devterm_printer.log
|
||||||
StandardError=file:/tmp/devterm_printer.err.log
|
StandardError=file:/tmp/devterm_printer.err.log
|
||||||
ExecStart=/usr/local/bin/devterm_thermal_printer.elf
|
ExecStart=/usr/local/bin/devterm_thermal_printer.elf
|
||||||
|
|||||||
106
Code/thermal_printer/ftype.c
Normal file
106
Code/thermal_printer/ftype.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include "ftype.h"
|
||||||
|
|
||||||
|
#include "utf8-utils.h"
|
||||||
|
|
||||||
|
static const UTF32 utf32_space[2] = {' ', 0};
|
||||||
|
|
||||||
|
bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
|
||||||
|
int req_size_w, int req_size_h, char **error) {
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
if (FT_Init_FreeType(ft) == 0) {
|
||||||
|
if (FT_New_Face(*ft, ttf_file, 0, face) == 0) {
|
||||||
|
|
||||||
|
if (FT_Set_Pixel_Sizes(*face, req_size_w, req_size_h) == 0) {
|
||||||
|
ret = true;
|
||||||
|
} else {
|
||||||
|
if (error)
|
||||||
|
*error = strdup("Can't set font size");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (error)
|
||||||
|
*error = strdup("Can't load TTF file");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (error)
|
||||||
|
*error = strdup("Can't init freetype library");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool change_ft_size(FT_Face face, int req_size_w, int req_size_h) {
|
||||||
|
bool ret = false;
|
||||||
|
if (FT_Set_Pixel_Sizes(face, req_size_w, req_size_h) == 0) {
|
||||||
|
ret = true;
|
||||||
|
} else {
|
||||||
|
printf("Can't set font size");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/*===========================================================================
|
||||||
|
done_ft
|
||||||
|
Clean up after we've finished wih the FreeType librar
|
||||||
|
=========================================================================*/
|
||||||
|
void done_ft(FT_Library ft) { FT_Done_FreeType(ft); }
|
||||||
|
|
||||||
|
/*===========================================================================
|
||||||
|
|
||||||
|
face_get_line_spacing
|
||||||
|
|
||||||
|
Get the nominal line spacing, that is, the distance between glyph
|
||||||
|
baselines for vertically-adjacent rows of text. This is "nominal" because,
|
||||||
|
in "real" typesetting, we'd need to add extra room for accents, etc.
|
||||||
|
|
||||||
|
=========================================================================*/
|
||||||
|
int face_get_line_spacing(FT_Face face) {
|
||||||
|
return face->size->metrics.height / 64;
|
||||||
|
// There are other possibilities the give subtly different results:
|
||||||
|
// return (face->bbox.yMax - face->bbox.yMin) / 64;
|
||||||
|
// return face->height / 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_slice_len(const char lb) {
|
||||||
|
|
||||||
|
if ((lb & 0x80) == 0)
|
||||||
|
return 1;
|
||||||
|
else if ((lb & 0xE0) == 0xC0)
|
||||||
|
return 2;
|
||||||
|
else if ((lb & 0xF0) == 0xE0)
|
||||||
|
return 3;
|
||||||
|
else if ((lb & 0xF8) == 0xF0)
|
||||||
|
return 4;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
UTF32 *cjk_utf8_to_utf32(const char *word) {
|
||||||
|
assert(word != NULL);
|
||||||
|
int l = strlen(word);
|
||||||
|
int u8l = utf8_strlen(word);
|
||||||
|
|
||||||
|
char buf[5];
|
||||||
|
|
||||||
|
UTF32 *ret = malloc((u8l + 1) * sizeof(UTF32));
|
||||||
|
int i = 0, j = 0;
|
||||||
|
int bskip = 1;
|
||||||
|
|
||||||
|
while (i < l) {
|
||||||
|
|
||||||
|
bskip = get_slice_len(word[i]);
|
||||||
|
strncpy(buf, &word[i], bskip);
|
||||||
|
if (bskip > 1) {
|
||||||
|
ret[j] = (UTF32)utf8_to_utf32(buf);
|
||||||
|
} else {
|
||||||
|
ret[j] = (UTF32)buf[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
j++;
|
||||||
|
i += bskip;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[u8l] = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
29
Code/thermal_printer/ftype.h
Normal file
29
Code/thermal_printer/ftype.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef FTYPE_H
|
||||||
|
#define FTYPE_H
|
||||||
|
// clang-format off
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <freetype2/ft2build.h>
|
||||||
|
|
||||||
|
#include <freetype/freetype.h>
|
||||||
|
// clang-format on
|
||||||
|
#ifndef UTF8
|
||||||
|
typedef unsigned char UTF8;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UTF32
|
||||||
|
typedef int32_t UTF32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool init_ft(const char *ttf_file, FT_Face *face, FT_Library *ft,
|
||||||
|
int req_size_w, int req_size_h, char **error);
|
||||||
|
|
||||||
|
bool change_ft_size(FT_Face face, int req_size_w, int req_size_h);
|
||||||
|
|
||||||
|
int face_get_line_spacing(FT_Face face);
|
||||||
|
|
||||||
|
int get_slice_len(const char lb);
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
//#define PRINT_SPLIT 6 // max points printed at the same time, 384/PRINT_SPLIT==96
|
//#define PRINT_SPLIT 6 // max points printed at the same time,
|
||||||
//#define MAX_PRINT_PTS 2
|
//384/PRINT_SPLIT==96 #define MAX_PRINT_PTS 2
|
||||||
|
|
||||||
void printer_send_data8(uint8_t);
|
void printer_send_data8(uint8_t);
|
||||||
|
|
||||||
@ -22,23 +22,26 @@ uint8_t feed_pitch1(uint64_t lines, uint8_t forward_backward);
|
|||||||
|
|
||||||
uint8_t bits_number(uint8_t n);
|
uint8_t bits_number(uint8_t n);
|
||||||
|
|
||||||
void print_dots_8bit_split(CONFIG*cfg,uint8_t *Array, uint8_t characters);
|
void print_dots_8bit_split(CONFIG *cfg, uint8_t *Array, uint8_t characters);
|
||||||
|
|
||||||
void print_dots_8bit(CONFIG*cfg,uint8_t *Array, uint8_t characters,uint8_t feed_num);
|
void print_dots_8bit(CONFIG *cfg, uint8_t *Array, uint8_t characters,
|
||||||
|
uint8_t feed_num);
|
||||||
|
|
||||||
uint16_t read_adc(char*);
|
uint16_t read_adc(char *);
|
||||||
uint16_t temperature();
|
uint16_t temperature();
|
||||||
int glob_file(char*);
|
int glob_file(char *);
|
||||||
|
uint16_t get_serial_cache_font_width(CONFIG *);
|
||||||
uint8_t print_lines8(CONFIG*);
|
uint8_t print_lines_ft(CONFIG *);
|
||||||
|
uint8_t print_lines8(CONFIG *);
|
||||||
|
|
||||||
uint8_t invert_bit(uint8_t a);
|
uint8_t invert_bit(uint8_t a);
|
||||||
|
|
||||||
uint8_t print_image8(CONFIG*);
|
uint8_t print_image8(CONFIG *);
|
||||||
void print_cut_line(CONFIG*);
|
void print_cut_line(CONFIG *);
|
||||||
|
|
||||||
void printer_set_font(CONFIG*cfg,uint8_t fnbits);
|
void printer_set_font_mode(CONFIG *cfg, int);
|
||||||
void parse_serial_stream(CONFIG*cfg,uint8_t input_ch);
|
void printer_set_font(CONFIG *cfg, uint8_t fnbits);
|
||||||
|
void parse_serial_stream(CONFIG *cfg, uint8_t input_ch);
|
||||||
|
|
||||||
void reset_cmd();
|
void reset_cmd();
|
||||||
|
|
||||||
|
|||||||
12
Code/thermal_printer/test.txt
Normal file
12
Code/thermal_printer/test.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
“励志一生”网站精心挑选汇集了60句宋词佳句,转载过来与大家分享,也很值得收藏!
|
||||||
|
|
||||||
|
1. 一ada;场消黯,永日无言,却下层楼。——柳永〈曲玉管〉
|
||||||
|
|
||||||
|
2. 可惜流asdfsad年,忧愁风雨,树犹如此。——辛弃疾〈水龙吟.登建康赏心亭〉
|
||||||
|
|
||||||
|
3. 十年生死两茫茫,不dsafadsf思量,自难忘。——苏轼〈江城子〉
|
||||||
|
|
||||||
|
4. 纵使相逢应不识,尘满面,鬓nbqga&*(如霜。——苏轼〈江城子〉
|
||||||
|
|
||||||
|
5. 相顾无言,惟有泪千行。——苏轼〈江城子〉
|
||||||
|
|
||||||
1
Code/thermal_printer/usr/local/etc/devterm-printer
Normal file
1
Code/thermal_printer/usr/local/etc/devterm-printer
Normal file
@ -0,0 +1 @@
|
|||||||
|
TTF=/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
|
||||||
83
Code/thermal_printer/utf8-utils.c
Normal file
83
Code/thermal_printer/utf8-utils.c
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/* Freetype GL - A C OpenGL Freetype engine
|
||||||
|
*
|
||||||
|
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
|
||||||
|
* file `LICENSE` for more details.
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
#include "utf8-utils.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------- utf8_surrogate_len ---
|
||||||
|
size_t
|
||||||
|
utf8_surrogate_len( const char* character )
|
||||||
|
{
|
||||||
|
size_t result = 0;
|
||||||
|
char test_char;
|
||||||
|
|
||||||
|
if (!character)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
test_char = character[0];
|
||||||
|
|
||||||
|
if ((test_char & 0x80) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
while (test_char & 0x80)
|
||||||
|
{
|
||||||
|
test_char <<= 1;
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ utf8_strlen ---
|
||||||
|
size_t
|
||||||
|
utf8_strlen( const char* string )
|
||||||
|
{
|
||||||
|
const char* ptr = string;
|
||||||
|
size_t result = 0;
|
||||||
|
|
||||||
|
while (*ptr)
|
||||||
|
{
|
||||||
|
ptr += utf8_surrogate_len(ptr);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
utf8_to_utf32( const char * character )
|
||||||
|
{
|
||||||
|
if( !character )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( character[0] & 0x80 ) == 0x0 )
|
||||||
|
{
|
||||||
|
return character[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( character[0] & 0xE0 ) == 0xC0 )
|
||||||
|
{
|
||||||
|
return ( ( character[0] & 0x3F ) << 6 ) | ( character[1] & 0x3F );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( character[0] & 0xF0 ) == 0xE0 )
|
||||||
|
{
|
||||||
|
return ( ( character[0] & 0x1F ) << ( 6 + 6 ) ) | ( ( character[1] & 0x3F ) << 6 ) | ( character[2] & 0x3F );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( character[0] & 0xF8 ) == 0xF0 )
|
||||||
|
{
|
||||||
|
return ( ( character[0] & 0x0F ) << ( 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[2] & 0x3F ) << 6 ) | ( character[3] & 0x3F );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( character[0] & 0xFC ) == 0xF8 )
|
||||||
|
{
|
||||||
|
return ( ( character[0] & 0x07 ) << ( 6 + 6 + 6 + 6 ) ) | ( ( character[1] & 0x3F ) << ( 6 + 6 + 6 ) ) | ( ( character[2] & 0x3F ) << ( 6 + 6 ) ) | ( ( character[3] & 0x3F ) << 6 ) | ( character[4] & 0x3F );
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xFFFD; // invalid character
|
||||||
|
}
|
||||||
68
Code/thermal_printer/utf8-utils.h
Normal file
68
Code/thermal_printer/utf8-utils.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* Freetype GL - A C OpenGL Freetype engine
|
||||||
|
*
|
||||||
|
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
|
||||||
|
* file `LICENSE` for more details.
|
||||||
|
*/
|
||||||
|
#ifndef __UTF8_UTILS_H__
|
||||||
|
#define __UTF8_UTILS_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
namespace ftgl {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file utf8-utils.h
|
||||||
|
* @author Marcel Metz <mmetz@adrian-broher.net>
|
||||||
|
*
|
||||||
|
* defgroup utf8-utils UTF-8 Utilities
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size in bytes of a given UTF-8 encoded character surrogate
|
||||||
|
*
|
||||||
|
* @param character An UTF-8 encoded character
|
||||||
|
*
|
||||||
|
* @return The length of the surrogate in bytes.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
utf8_surrogate_len( const char* character );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the length of the given UTF-8 encoded and
|
||||||
|
* NULL terminated string.
|
||||||
|
*
|
||||||
|
* @param string An UTF-8 encoded string
|
||||||
|
*
|
||||||
|
* @return The length of the string in characters.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
utf8_strlen( const char* string );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a given UTF-8 encoded character to its UTF-32 LE equivalent
|
||||||
|
*
|
||||||
|
* @param character An UTF-8 encoded character
|
||||||
|
*
|
||||||
|
* @return The equivalent of the given character in UTF-32 LE
|
||||||
|
* encoding.
|
||||||
|
*/
|
||||||
|
uint32_t
|
||||||
|
utf8_to_utf32( const char * character );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* #define __UTF8_UTILS_H__ */
|
||||||
@ -1,16 +1,15 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void delayus(unsigned int _us){
|
void delayus(unsigned int _us) { delayMicroseconds(_us); }
|
||||||
delayMicroseconds(_us);
|
|
||||||
|
uint8_t invert_bit(uint8_t a) {
|
||||||
|
|
||||||
|
return ((a & 0x01) << 7) | ((a & 0x02) << 5) | ((a & 0x04) << 3) |
|
||||||
|
((a & 0x08) << 1) | ((a & 0x10) >> 1) | ((a & 0x20) >> 3) |
|
||||||
|
((a & 0x40) >> 5) | ((a & 0x80) >> 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t invert_bit(uint8_t a){
|
uint8_t bits_number(uint8_t n) // count bits "1"
|
||||||
|
|
||||||
return ((a&0x01)<<7)|((a&0x02)<<5)|((a&0x04)<<3)|((a&0x08)<<1)|((a&0x10)>>1)|((a&0x20)>>3)|((a&0x40)>>5)|((a&0x80)>>7);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t bits_number(uint8_t n)//count bits "1"
|
|
||||||
{
|
{
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
while (n) {
|
while (n) {
|
||||||
@ -19,6 +18,3 @@ uint8_t bits_number(uint8_t n)//count bits "1"
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,26 @@
|
|||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <wiringPi.h>
|
#include <wiringPi.h>
|
||||||
|
|
||||||
#define SEP printf(" ");
|
#define SEP printf(" ");
|
||||||
// a is string, b is number
|
// a is string, b is number
|
||||||
#define DEBUG(a,b) printf(a);SEP;printf("%d\n",b);
|
#define DEBUG(a, b) \
|
||||||
|
printf(a); \
|
||||||
|
SEP; \
|
||||||
|
printf("%d\n", b);
|
||||||
|
|
||||||
#define ALINE printf("\n");
|
#define ALINE printf("\n");
|
||||||
|
|
||||||
#define PRINTF(...) { printf(__VA_ARGS__);fflush(stdout);}
|
#define PRINTF(...) \
|
||||||
|
{ \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
fflush(stdout); \
|
||||||
|
}
|
||||||
|
|
||||||
void delayus(unsigned int _us);
|
void delayus(unsigned int _us);
|
||||||
|
|
||||||
@ -21,5 +28,4 @@ uint8_t invert_bit(uint8_t a);
|
|||||||
|
|
||||||
uint8_t bits_number(uint8_t n);
|
uint8_t bits_number(uint8_t n);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user