function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
Chip_Clock_SetUSBClockSource
|
void Chip_Clock_SetUSBClockSource(CHIP_SYSCTL_USBCLKSRC_T src, uint32_t div)
{
LPC_SYSCTL->USBCLKSEL = (uint32_t) src;
LPC_SYSCTL->USBCLKUEN = 0;
LPC_SYSCTL->USBCLKUEN = 1;
LPC_SYSCTL->USBCLKDIV = div;
}
|
/* Set USB clock source and divider */
|
Set USB clock source and divider
|
Chip_Clock_SetWDTClockSource
|
void Chip_Clock_SetWDTClockSource(CHIP_SYSCTL_WDTCLKSRC_T src, uint32_t div)
{
LPC_SYSCTL->WDTCLKSEL = (uint32_t) src;
LPC_SYSCTL->WDTCLKUEN = 0;
LPC_SYSCTL->WDTCLKUEN = 1;
LPC_SYSCTL->WDTCLKDIV = div;
}
|
/* Set WDT clock source and divider */
|
Set WDT clock source and divider
|
Chip_Clock_GetWDTOSCRate
|
uint32_t Chip_Clock_GetWDTOSCRate(void)
{
return Chip_Clock_GetWDTLFORate(LPC_SYSCTL->WDTOSCCTRL);
}
|
/* Return estimated watchdog oscillator rate */
|
Return estimated watchdog oscillator rate
|
Chip_Clock_GetLFOOSCRate
|
uint32_t Chip_Clock_GetLFOOSCRate(void)
{
return Chip_Clock_GetWDTLFORate(LPC_SYSCTL->LFOSCCTRL);
}
|
/* Return estimated low frequency oscillator rate */
|
Return estimated low frequency oscillator rate
|
Chip_Clock_GetSystemPLLInClockRate
|
uint32_t Chip_Clock_GetSystemPLLInClockRate(void)
{
uint32_t clkRate;
switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->SYSPLLCLKSEL & 0x3)) {
case SYSCTL_PLLCLKSRC_IRC:
clkRate = Chip_Clock_GetIntOscRate();
break;
case SYSCTL_PLLCLKSRC_MAINOSC:
clkRate = Chip_Clock_GetMainOscRate();
break;
#if defined(CHIP_LPC11AXX)
case SYSCTL_PLLCLKSRC_EXT_CLKIN:
clkRate = Chip_Clock_GetExtClockInRate();
break;
#endif
default:
clkRate = 0;
}
return clkRate;
}
|
/* Return System PLL input clock rate */
|
Return System PLL input clock rate
|
Chip_Clock_GetSystemPLLOutClockRate
|
uint32_t Chip_Clock_GetSystemPLLOutClockRate(void)
{
return Chip_Clock_GetPLLFreq(LPC_SYSCTL->SYSPLLCTRL,
Chip_Clock_GetSystemPLLInClockRate());
}
|
/* Return System PLL output clock rate */
|
Return System PLL output clock rate
|
Chip_Clock_GetUSBPLLInClockRate
|
uint32_t Chip_Clock_GetUSBPLLInClockRate(void)
{
uint32_t clkRate;
switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->USBPLLCLKSEL & 0x3)) {
case SYSCTL_PLLCLKSRC_IRC:
clkRate = Chip_Clock_GetIntOscRate();
break;
case SYSCTL_PLLCLKSRC_MAINOSC:
clkRate = Chip_Clock_GetMainOscRate();
break;
default:
clkRate = 0;
}
return clkRate;
}
|
/* Return USB PLL input clock rate */
|
Return USB PLL input clock rate
|
Chip_Clock_GetUSBPLLOutClockRate
|
uint32_t Chip_Clock_GetUSBPLLOutClockRate(void)
{
return Chip_Clock_GetPLLFreq(LPC_SYSCTL->USBPLLCTRL,
Chip_Clock_GetUSBPLLInClockRate());
}
|
/* Return USB PLL output clock rate */
|
Return USB PLL output clock rate
|
Chip_Clock_GetMainClockRate
|
uint32_t Chip_Clock_GetMainClockRate(void)
{
uint32_t clkRate = 0;
switch ((CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL & 0x3)) {
case SYSCTL_MAINCLKSRC_IRC:
clkRate = Chip_Clock_GetIntOscRate();
break;
case SYSCTL_MAINCLKSRC_PLLIN:
clkRate = Chip_Clock_GetSystemPLLInClockRate();
break;
#if defined(CHIP_LPC11AXX)
case SYSCTL_MAINCLKSRC_LFOSC:
clkRate = Chip_Clock_GetLFOOSCRate();
break;
#else
case SYSCTL_MAINCLKSRC_WDTOSC:
clkRate = Chip_Clock_GetWDTOSCRate();
break;
#endif
case SYSCTL_MAINCLKSRC_PLLOUT:
clkRate = Chip_Clock_GetSystemPLLOutClockRate();
break;
}
return clkRate;
}
|
/* Return main clock rate */
|
Return main clock rate
|
Chip_Clock_GetSystemClockRate
|
uint32_t Chip_Clock_GetSystemClockRate(void)
{
/* No point in checking for divide by 0 */
return Chip_Clock_GetMainClockRate() / LPC_SYSCTL->SYSAHBCLKDIV;
}
|
/* Return system clock rate */
|
Return system clock rate
|
Chip_SYSCTL_SetDeepSleepPD
|
void Chip_SYSCTL_SetDeepSleepPD(uint32_t sleepmask)
{
/* Update new value */
LPC_SYSCTL->PDSLEEPCFG = PDSLEEPMASK | (sleepmask & PDSLEEPMASKTMP);
}
|
/* Setup deep sleep behaviour for power down */
|
Setup deep sleep behaviour for power down
|
Chip_SYSCTL_SetWakeup
|
void Chip_SYSCTL_SetWakeup(uint32_t wakeupmask)
{
/* Update new value */
LPC_SYSCTL->PDWAKECFG = PDWAKEUPUSEMASK | (wakeupmask & PDWAKEUPMASKTMP);
}
|
/* Setup wakeup behaviour from deep sleep */
|
Setup wakeup behaviour from deep sleep
|
Chip_SYSCTL_PowerDown
|
void Chip_SYSCTL_PowerDown(uint32_t powerdownmask)
{
uint32_t pdrun;
pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP;
pdrun |= (powerdownmask & PDRUNCFGMASKTMP);
LPC_SYSCTL->PDRUNCFG = (pdrun | PDRUNCFGUSEMASK);
}
|
/* Power down one or more blocks or peripherals */
|
Power down one or more blocks or peripherals
|
Chip_SYSCTL_PowerUp
|
void Chip_SYSCTL_PowerUp(uint32_t powerupmask)
{
uint32_t pdrun;
pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP;
pdrun &= ~(powerupmask & PDRUNCFGMASKTMP);
LPC_SYSCTL->PDRUNCFG = (pdrun | PDRUNCFGUSEMASK);
}
|
/* Power up one or more blocks or peripherals */
|
Power up one or more blocks or peripherals
|
u8x8_SetBitmapDeviceSize
|
static uint8_t u8x8_SetBitmapDeviceSize(u8x8_t *u8x8, uint16_t pixel_width, uint16_t pixel_height)
{
/* update the global bitmap object, allocate the bitmap */
if ( u8x8_bitmap_SetSize(&u8x8_bitmap, pixel_width, pixel_height) == 0 )
return 0;
/* update the u8x8 object */
u8x8_bitmap_info.tile_width = (pixel_width+7)/8;
u8x8_bitmap_info.tile_height = (pixel_height+7)/8;
u8x8_bitmap_info.pixel_width = pixel_width;
u8x8_bitmap_info.pixel_height = pixel_height;
return 1;
}
|
/* will be called by u8x8_SetupBitmap or u8g2_SetupBitmap */
|
will be called by u8x8_SetupBitmap or u8g2_SetupBitmap
|
u8x8_DrawBitmapTiles
|
static void u8x8_DrawBitmapTiles(u8x8_t *u8x8, uint16_t tx, uint16_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
{
u8x8_bitmap_DrawTiles(&u8x8_bitmap, tx, ty, tile_cnt, tile_ptr);
}
|
/* draw tiles to the bitmap, called by the device procedure */
|
draw tiles to the bitmap, called by the device procedure
|
u8x8_SetupBitmap
|
void u8x8_SetupBitmap(u8x8_t *u8x8, uint16_t pixel_width, uint16_t pixel_height)
{
u8x8_SetBitmapDeviceSize(u8x8, pixel_width, pixel_height);
/* setup defaults */
u8x8_SetupDefaults(u8x8);
/* setup specific callbacks */
u8x8->display_cb = u8x8_d_bitmap;
/* setup display info */
u8x8_SetupMemory(u8x8);
}
|
/* u8x8 and u8g2 setup functions */
|
u8x8 and u8g2 setup functions
|
u8x8_ConnectBitmapToU8x8
|
uint8_t u8x8_ConnectBitmapToU8x8(u8x8_t *u8x8)
{
if ( u8x8_SetBitmapDeviceSize(u8x8, u8x8_GetCols(u8x8)*8, u8x8_GetRows(u8x8)*8) == 0 )
return 0;
u8x8_bitmap.u8x8_bitmap_display_old_cb = u8x8->display_cb;
u8x8->display_cb = u8x8_d_bitmap_chain;
return 1;
}
|
/* connect the bitmap to an existing u8g2 or u8x8 object */
|
connect the bitmap to an existing u8g2 or u8x8 object
|
u8g2_ll_hvline_xbm
|
void u8g2_ll_hvline_xbm(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
if ( dir == 0 )
{
do
{
u8g2_draw_pixel_horizontal_xbm(u8g2, x, y);
x++;
len--;
} while( len != 0 );
}
else
{
do
{
u8g2_draw_pixel_horizontal_xbm(u8g2, x, y);
y++;
len--;
} while( len != 0 );
}
}
|
/*
x,y Upper left position of the line within the local buffer (not the display!)
len length of the line in pixel, len must not be 0
dir 0: horizontal line (left to right)
1: vertical line (top to bottom)
asumption:
all clipping done
*/
|
x,y Upper left position of the line within the local buffer (not the display!) len length of the line in pixel, len must not be 0 dir 0: horizontal line (left to right) 1: vertical line (top to bottom) asumption: all clipping done
|
me_cb_null
|
int me_cb_null(menu_t *menu, const me_t *me, uint8_t msg)
{
return 0;
}
|
/* this function must be the last function in the list. it also marks the end of a list */
|
this function must be the last function in the list. it also marks the end of a list
|
me_cb_0_5
|
int me_cb_0_5(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_SELECT:
{
uint8_t val = *(uint8_t *)(me->val);
val++;
if ( val > 5 )
val = 0;
*(uint8_t *)(me->val) = val;
}
return 1;
}
return me_cb_0_9(menu, me, msg);
}
|
/*
Name: me_cb_0_5
Val: uint8_t *
*/
|
Name: me_cb_0_5 Val: uint8_t *
|
me_cb_0_55
|
int me_cb_0_55(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_SELECT:
{
uint8_t val = *(uint8_t *)(me->val);
val+=5;
if ( val > 55 )
val = 0;
*(uint8_t *)(me->val) = val;
}
return 1;
}
return me_cb_0_23(menu, me, msg);
}
|
/*
Name: me_cb_0_55
Val: uint8_t *
*/
|
Name: me_cb_0_55 Val: uint8_t *
|
me_cb_1_12
|
int me_cb_1_12(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_SELECT:
{
uint8_t val = *(uint8_t *)(me->val);
val++;
if ( val > 12 )
val = 1;
*(uint8_t *)(me->val) = val;
}
return 1;
}
return me_cb_0_23(menu, me, msg);
}
|
/*
Name: me_cb_1_12
Val: uint8_t *
*/
|
Name: me_cb_1_12 Val: uint8_t *
|
me_cb_1_31
|
int me_cb_1_31(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_SELECT:
{
uint8_t val = *(uint8_t *)(me->val);
val++;
if ( val > 31 )
val = 1;
*(uint8_t *)(me->val) = val;
}
return 1;
}
return me_cb_0_23(menu, me, msg);
}
|
/*
Name: me_cb_1_31
Val: uint8_t *
*/
|
Name: me_cb_1_31 Val: uint8_t *
|
me_cb_num_label
|
int me_cb_num_label(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_IS_FOCUS:
case ME_MSG_DRAW_FOCUS:
case ME_MSG_SELECT:
break;
case ME_MSG_DRAW:
u8g2_SetFont(menu->u8g2, MENU_BIG_NUM);
u8g2_DrawUTF8(menu->u8g2, me->x, me->y, (char *)(me->arg) );
return 1;
}
return 0;
}
|
/*
Name: me_cb_num_label
can not get focus
Arg: char *
*/
|
Name: me_cb_num_label can not get focus Arg: char *
|
me_cb_button_empty
|
int me_cb_button_empty(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_IS_FOCUS )
return 1;
if ( me->val != NULL )
return ((me_cb)(me->val))(menu, me, msg);
return 0;
}
|
/*
Name: me_cb_button_empty
Val: callback function
Arg: not used
*/
|
Name: me_cb_button_empty Val: callback function Arg: not used
|
me_cb_label
|
int me_cb_label(menu_t *menu, const me_t *me, uint8_t msg)
{
switch(msg)
{
case ME_MSG_IS_FOCUS:
case ME_MSG_DRAW_FOCUS:
case ME_MSG_SELECT:
break;
case ME_MSG_DRAW:
u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT);
u8g2_DrawUTF8(menu->u8g2, me->x, me->y, (char *)(me->arg) );
return 1;
}
return 0;
}
|
/*
Name: me_cb_label
can not get focus
Arg: char *
*/
|
Name: me_cb_label can not get focus Arg: char *
|
menu_CallME
|
int menu_CallME(menu_t *menu, uint8_t msg)
{
const me_t *me;
me = menu->me_list+menu->current_index;
return me->cb(menu, me, msg);
}
|
/* call menu element from menu->current_index */
|
call menu element from menu->current_index
|
menu_CalcNextValidFocus
|
static void menu_CalcNextValidFocus(menu_t *menu)
{
for(;;)
{
menu->current_index = menu->focus_index;
if ( menu->current_index >= menu->me_count )
break;
if ( menu_CallME(menu, ME_MSG_IS_FOCUS) != 0 )
break;
menu->focus_index++;
}
}
|
/* stay on current focus if valid, move to next valid focus */
|
stay on current focus if valid, move to next valid focus
|
menu_NextFocus
|
void menu_NextFocus(menu_t *menu)
{
menu->focus_index++;
if ( menu->focus_index >= menu->me_count )
menu->focus_index = 0;
menu_CalcNextValidFocus(menu);
}
|
/* advance current focus to the next element */
|
advance current focus to the next element
|
menu_Select
|
void menu_Select(menu_t *menu)
{
menu->current_index = menu->focus_index;
menu_CallME(menu, ME_MSG_SELECT);
}
|
/* send select message to the element which has the current focus */
|
send select message to the element which has the current focus
|
me_action_save_date
|
int me_action_save_date(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
{
gui_date_adjust(); /* calculate the weekday */
set_date(gui_data.year_t, gui_data.year_o, gui_data.month / 10, gui_data.month % 10, gui_data.day / 10 , gui_data.day % 10, gui_data.weekday);
menu_SetMEList(menu, melist_setup_menu, 0); /* first set the normal menu */
gui_Recalculate(); /* because it might be overwritten with the alarm menu */
return 1;
}
return 0;
}
|
/* Date Edit Dialog */
|
Date Edit Dialog
|
me_action_goto_boot_info
|
int me_action_goto_boot_info(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
{
menu_SetMEList(menu, melist_boot_info_menu, 0);
return 1;
}
return 0;
}
|
/* System 2 Menu */
|
System 2 Menu
|
is_leap_year
|
uint8_t is_leap_year(uint16_t y)
{
if (
((y % 4 == 0) && (y % 100 != 0)) ||
(y % 400 == 0)
)
return 1;
return 0;
}
|
/*
Prototype:
uint8_t is_leap_year(uint16_t y)
Description:
Calculate leap year
Arguments:
y year, e.g. 2011 for year 2011
Result:
0 not a leap year
1 leap year
*/
|
Prototype: uint8_t is_leap_year(uint16_t y) Description: Calculate leap year Arguments: y year, e.g. 2011 for year 2011 Result: 0 not a leap year 1 leap year
|
get_year_day_number
|
uint16_t get_year_day_number(uint16_t y, uint8_t m, uint8_t d)
{
uint8_t tmp1;
uint16_t tmp2;
tmp1 = 0;
if ( m >= 3 )
tmp1++;
tmp2 = m;
tmp2 +=2;
tmp2 *=611;
tmp2 /= 20;
tmp2 += d;
tmp2 -= 91;
tmp1 <<=1;
tmp2 -= tmp1;
if ( tmp1 != 0 )
tmp2 += is_leap_year(y);
return tmp2;
}
|
/*
Prototype:
uint16_t get_year_day_number(uint16_t y, uint8_t m, uint8_t d)
Description:
Calculate the day number within a year. 1st of Jan has the number 1.
"Robertson" Algorithm IDAY (CACM Vol 15/#10/Oct 1972)
Arguments:
y year, e.g. 2011 for year 2011
m month with 1 = january to 12 = december
d day starting with 1
Result:
The "day number" within the year: 1 for the 1st of Jan.
See also:
get_month_by_day_number()
*/
|
Prototype: uint16_t get_year_day_number(uint16_t y, uint8_t m, uint8_t d) Description: Calculate the day number within a year. 1st of Jan has the number 1. "Robertson" Algorithm IDAY (CACM Vol 15/#10/Oct 1972) Arguments: y year, e.g. 2011 for year 2011 m month with 1 = january to 12 = december d day starting with 1 Result: The "day number" within the year: 1 for the 1st of Jan. See also: get_month_by_day_number()
|
corrected_year_day_number
|
static uint16_t corrected_year_day_number(uint16_t y, uint16_t ydn)
{
uint8_t a;
a = is_leap_year(y);
if ( ydn > 59+a )
{
ydn += 2;
ydn -= a;
}
ydn += 91;
return ydn;
}
|
/*
Prototype:
uint8_t get_month_by_year_day_number(uint16_t y, uint16_t ydn)
Description:
Get the month from year and day number within a year.
"R. A. Stone" Algorithm (CACM Vol 13/#10/Oct 1970)
Arguments:
y year, e.g. 2011 for year 2011
ydn year day number (1st of Jan has the number 1)
Result:
The month within the year: 1 for January.
See also:
get_year_day_number()
*/
|
Prototype: uint8_t get_month_by_year_day_number(uint16_t y, uint16_t ydn) Description: Get the month from year and day number within a year. "R. A. Stone" Algorithm (CACM Vol 13/#10/Oct 1970) Arguments: y year, e.g. 2011 for year 2011 ydn year day number (1st of Jan has the number 1) Result: The month within the year: 1 for January. See also: get_year_day_number()
|
get_day_by_year_day_number
|
uint8_t get_day_by_year_day_number(uint16_t y, uint16_t ydn)
{
uint8_t m;
uint16_t tmp;
m = get_month_by_year_day_number(y, ydn);
m += 2;
ydn = corrected_year_day_number(y, ydn);
tmp = 611;
tmp *= m;
tmp /= 20;
ydn -= tmp;
return ydn;
}
|
/*
Prototype:
uint8_t get_day_by_year_day_number(uint16_t y, uint16_t ydn)
Description:
Get the day within month from year and day number within a year.
"R. A. Stone" Algorithm (CACM Vol 13/#10/Oct 1970)
Arguments:
y year, e.g. 2011 for year 2011
ydn year day number (1st of Jan has the number 1)
Result:
The day within a month: 1 for the first day of a month.
See also:
get_year_day_number()
*/
|
Prototype: uint8_t get_day_by_year_day_number(uint16_t y, uint16_t ydn) Description: Get the day within month from year and day number within a year. "R. A. Stone" Algorithm (CACM Vol 13/#10/Oct 1970) Arguments: y year, e.g. 2011 for year 2011 ydn year day number (1st of Jan has the number 1) Result: The day within a month: 1 for the first day of a month. See also: get_year_day_number()
|
get_weekday_by_year_day_number
|
uint8_t get_weekday_by_year_day_number(uint16_t y, uint16_t ydn)
{
uint8_t j, c, tmp8;
uint16_t tmp16;
y--;
j = y % 100;
c = y / 100;
tmp16 = c;
tmp16 *= 5;
tmp16 += ydn;
tmp8 = j;
j >>= 2;
c >>= 2;
tmp8 += j;
tmp8 += c;
tmp8 += 28;
tmp16 += tmp8;
tmp16 %= 7;
return tmp16;
}
|
/*
Prototype:
uint8_t get_weekday_by_year_day_number(uint16_t y, uint16_t ydn)
Description:
Get the day within week from year and day number within a year.
"Zeller" Algorithm
https://de.wikisource.org/wiki/Index:Acta_Mathematica_vol._009_(1886)
https://ia801407.us.archive.org/8/items/actamathematica09upps/actamathematica09upps.pdf
Arguments:
y year, e.g. 2011 for year 2011
ydn year day number (1st of Jan has the number 1)
Result:
The day within a week: 0..6 with 0 = Sunday, 1 = Monday, ...
See also:
get_year_day_number()
*/
|
Prototype: uint8_t get_weekday_by_year_day_number(uint16_t y, uint16_t ydn) Description: Get the day within week from year and day number within a year. "Zeller" Algorithm https://de.wikisource.org/wiki/Index:Acta_Mathematica_vol._009_(1886) https://ia801407.us.archive.org/8/items/actamathematica09upps/actamathematica09upps.pdf Arguments: y year, e.g. 2011 for year 2011 ydn year day number (1st of Jan has the number 1) Result: The day within a week: 0..6 with 0 = Sunday, 1 = Monday, ... See also: get_year_day_number()
|
to_century_day_number
|
uint16_t to_century_day_number(uint16_t y, uint16_t ydn)
{
uint16_t cdn;
cdn = ydn;
cdn--;
while( y > 2000 )
{
y--;
cdn += 365;
cdn += is_leap_year(y);
}
return cdn;
}
|
/*
Prototype:
uint16_t to_century_day_number(uint16_t y, uint16_t ydn)
Description:
Calculate days since January, 1st, 2000
Arguments:
y year, e.g. 2011 for year 2011
ydn year day number (1st of Jan has the number 1)
*/
|
Prototype: uint16_t to_century_day_number(uint16_t y, uint16_t ydn) Description: Calculate days since January, 1st, 2000 Arguments: y year, e.g. 2011 for year 2011 ydn year day number (1st of Jan has the number 1)
|
to_time
|
uint32_t to_time(uint16_t cdn, uint8_t h, uint8_t m, uint8_t s)
{
uint32_t t;
t = cdn;
t *= 24;
t += h;
t *= 60;
t += m;
t *= 60;
t += s;
return t;
}
|
/*
Calculate the seconds after 2000-01-01 00:00. The largest possible
time is 2136-02-07 06:28:15
*/
|
Calculate the seconds after 2000-01-01 00:00. The largest possible time is 2136-02-07 06:28:15
|
to_minutes
|
uint32_t to_minutes(uint16_t cdn, uint8_t h, uint8_t m)
{
uint32_t t;
t = cdn;
t *= 24;
t += h;
t *= 60;
t += m;
return t;
}
|
/*
Calculate the minutes after 2000-01-01 00:00.
*/
|
Calculate the minutes after 2000-01-01 00:00.
|
gui_calc_week_time
|
void gui_calc_week_time(void)
{
gui_data.week_time = gui_data.weekday;
gui_data.week_time *= 24;
gui_data.week_time += gui_data.h;
gui_data.week_time *= 60;
gui_data.week_time += gui_data.mt * 10 + gui_data.mo;
}
|
/*
calculate the minute within the week.
this must be called after gui_date_adjust(), because the weekday is used here
*/
|
calculate the minute within the week. this must be called after gui_date_adjust(), because the weekday is used here
|
gui_Recalculate
|
void gui_Recalculate(void)
{
int i;
gui_date_adjust();
gui_calc_week_time();
gui_calc_next_alarm();
for ( i = 0; i < GUI_ALARM_CNT; i++ )
{
gui_alarm_calc_str_time(i);
}
gui_StoreData();
}
|
/* recalculate all internal data */
|
recalculate all internal data
|
gui_SignalTimeChange
|
void gui_SignalTimeChange(void)
{
/* recalculate dependent values */
gui_Recalculate();
/* setup menu */
menu_SetMEList(&gui_menu, melist_display_time, 0);
/* enable alarm */
if ( gui_data.is_alarm != 0 )
{
menu_SetMEList(&gui_menu, melist_active_alarm_menu, 0);
enable_alarm();
}
}
|
/* additionally the active alarm menu might be set by this function */
|
additionally the active alarm menu might be set by this function
|
set_contrast
|
void set_contrast(void)
{
}
|
/* set contrast to gui_data.contrast, value 1..7, 0 is default (do not set) */
|
set contrast to gui_data.contrast, value 1..7, 0 is default (do not set)
|
obj_list_GetEmpty
|
uint8_t obj_list_GetEmpty(void)
{
uint8_t i;
for( i = 0; i < OBJ_LIST_MAX; i++ )
if ( obj_list[i].tile == 0 )
return i;
return 255;
}
|
/* 255 means "not found" */
|
255 means "not found"
|
map_SetWindowPos
|
void map_SetWindowPos(map_t *m, v16_t *newpos)
{
v16_t v;
v16_SetByV16(&(m->vwpp), newpos );
v16_SetByV16(&(m->vwpt), newpos );
v16_RightShift(&(m->vwpt), 4);
v16_SetByV16(&v, &(m->vwpt));
v16_LeftShift(&v, 4);
v16_SetByV16(&(m->dtwp), &(m->vwpp));
v16_Sub(&(m->dtwp), &v);
//printf("vwpp.v[0]=%u vwpt.v[0]=%u delta-x=%u tmw=%u\n", m->vwpp.v[0], m->vwpt.v[0], m->dtwp.v[0], m->tmw);
//printf("vwpp.v[1]=%u vwpt.v[1]=%u delta-y=%u tmh=%u\n", m->vwpp.v[1], m->vwpt.v[1], m->dtwp.v[1], m->tmh);
}
|
/* set the position of the visible window in the map */
|
set the position of the visible window in the map
|
map_IsOccupied
|
int map_IsOccupied(map_t *m, v16_t *pos_t)
{
uint8_t tile;
tile = map_GetTile(m, pos_t->v[0], pos_t->v[1]);
if ( tile == 32 )
return 0;
return 1;
}
|
/* check whether the target object is occupied */
|
check whether the target object is occupied
|
map_isOccupiedInDir
|
int map_isOccupiedInDir(map_t *m, v16_t *pos_t, uint8_t dir)
{
v16_t tmp;
v16_SetByV16(&tmp, pos_t);
v16_AddDir(&tmp, dir, 1);
return map_IsOccupied(m, &tmp);
}
|
/* check whether tile in direction dir is occpied */
|
check whether tile in direction dir is occpied
|
map_GetDisplayPosByTileMapPos
|
void map_GetDisplayPosByTileMapPos(map_t *m, v16_t *dest_pos_pix, v16_t *src_tile_pos)
{
v16_SetByV16(dest_pos_pix, src_tile_pos );
v16_Sub(dest_pos_pix, &(m->vwpt)); /* upper left tile corner of the visible area */
v16_LeftShift(dest_pos_pix, 4); /* convert to pixel */
v16_Sub(dest_pos_pix, &(m->dtwp)); /* add the offset of the upper left tile corner */
v16_Add(dest_pos_pix, &(m->vis_win_disp_pos_pix)); /* add display offset */
}
|
/* for a position on the map (tile coordinates) return pixel pos on display */
|
for a position on the map (tile coordinates) return pixel pos on display
|
st_GetObj
|
static st_obj *st_GetObj(uint8_t objnr)
{
return st_objects+objnr;
}
|
/*
for the specified index number, return the object
*/
|
for the specified index number, return the object
|
st_GetMissleMask
|
uint8_t st_GetMissleMask(uint8_t objnr)
{
st_obj *o = st_GetObj(objnr);
return u8x8_pgm_read(&(st_object_types[o->ot].missle_mask));
}
|
/*
check, if this is a missle-like object (that is, can this object destroy something else)
*/
|
check, if this is a missle-like object (that is, can this object destroy something else)
|
st_GetHitMask
|
uint8_t st_GetHitMask(uint8_t objnr)
{
st_obj *o = st_GetObj(objnr);
return u8x8_pgm_read(&(st_object_types[o->ot].hit_mask));
}
|
/*
check, if this is a missle-like object (that is, can this object destroy something else)
*/
|
check, if this is a missle-like object (that is, can this object destroy something else)
|
st_FindObj
|
int8_t st_FindObj(uint8_t ot)
{
int8_t i;
for( i = 0; i < ST_OBJ_CNT; i++ )
{
if ( st_objects[i].ot == ot )
return i;
}
return -1;
}
|
/*
search an empty object
*/
|
search an empty object
|
st_ClrObjs
|
void st_ClrObjs(void)
{
int8_t i;
for( i = 0; i < ST_OBJ_CNT; i++ )
st_objects[i].ot = 0;
}
|
/*
delete all objects
*/
|
delete all objects
|
st_NewObj
|
int8_t st_NewObj(void)
{
int8_t i;
for( i = 0; i < ST_OBJ_CNT; i++ )
{
if ( st_objects[i].ot == 0 )
return i;
}
return -1;
}
|
/*
search an empty object
*/
|
search an empty object
|
st_CalcXY
|
uint8_t st_CalcXY(st_obj *o)
{
//st_obj *o = st_GetObj(objnr);
st_px_y = o->y>>ST_FP;
st_px_x = o->x>>ST_FP;
return st_px_x;
}
|
/* pixel within area */
|
pixel within area
|
st_NewGadget
|
void st_NewGadget(uint8_t x, uint8_t y)
{
st_obj *o;
int8_t objnr = st_NewObj();
if ( objnr < 0 )
return;
o = st_GetObj(objnr);
st_SetXY(o, x, y);
o->ot = ST_OT_GADGET;
o->tmp = 8;
//o->x = (x)<<ST_FP;
//o->y = (y)<<ST_FP;
o->x0 = -3;
o->x1 = 1;
o->y0 = -2;
o->y1 = 2;
}
|
/*
x,y are pixel coordinats within the play arey
*/
|
x,y are pixel coordinats within the play arey
|
st_NewTrashDust
|
void st_NewTrashDust(uint8_t x, uint8_t y, int ot)
{
st_obj *o;
int8_t objnr = st_NewObj();
if ( objnr < 0 )
return;
o = st_GetObj(objnr);
o->ot = ot;
st_SetXY(o, x, y);
//o->x = (x)<<ST_FP;
//o->y = (y)<<ST_FP;
o->x0 = 0;
o->x1 = 0;
o->y0 = -2;
o->y1 = 2;
}
|
/*
x,y are pixel coordinats within the play arey
*/
|
x,y are pixel coordinats within the play arey
|
is_leap_year
|
static uint8_t is_leap_year(uint16_t y)
{
if (
((y % 4 == 0) && (y % 100 != 0)) ||
(y % 400 == 0)
)
return 1;
return 0;
}
|
/*
Prototype:
uint8_t is_leap_year(uint16_t y)
Description:
Calculate leap year
Arguments:
y year, e.g. 2011 for year 2011
Result:
0 not a leap year
1 leap year
*/
|
Prototype: uint8_t is_leap_year(uint16_t y) Description: Calculate leap year Arguments: y year, e.g. 2011 for year 2011 Result: 0 not a leap year 1 leap year
|
gui_Recalculate
|
void gui_Recalculate(void)
{
int i;
gui_date_adjust();
gui_calc_week_time();
gui_calc_next_alarm();
for ( i = 0; i < GUI_ALARM_CNT; i++ )
{
gui_alarm_calc_str_time(i);
}
}
|
/* additionally the active alarm menu might be set by this function */
|
additionally the active alarm menu might be set by this function
|
me_action_save_date
|
int me_action_save_date(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
{
menu_SetMEList(menu, melist_top_menu, 0); /* first set the normal menu */
gui_Recalculate(); /* because it might be overwritten with the alarm menu */
return 1;
}
return 0;
}
|
/* Date Edit Dialog */
|
Date Edit Dialog
|
stack_GetCurrElement
|
struct _stack_element_struct *stack_GetCurrElement(void)
{
return lrc_obj.curr_element;
}
|
/* get current element from stack */
|
get current element from stack
|
stack_InitCurrElement
|
void stack_InitCurrElement(void)
{
stack_element_p e = stack_GetCurrElement();
e->best_eval = EVAL_T_MIN;
e->best_from_pos = ILLEGAL_POSITION;
e->best_to_pos = ILLEGAL_POSITION;
}
|
/* reset the current element on the stack */
|
reset the current element on the stack
|
stack_Init
|
void stack_Init(uint8_t max)
{
lrc_obj.curr_depth = 0;
lrc_obj.curr_element = lrc_obj.stack_memory;
lrc_obj.max_depth = max;
lrc_obj.check_mode = CHECK_MODE_NONE;
stack_InitCurrElement();
stack_GetCurrElement()->current_color = lrc_obj.ply_count;
stack_GetCurrElement()->current_color &= 1;
}
|
/* resets the search stack (and the check mode) */
|
resets the search stack (and the check mode)
|
stack_SetMove
|
void stack_SetMove(eval_t val, uint8_t to_pos)
{
stack_element_p e = stack_GetCurrElement();
if ( e->best_eval < val )
{
e->best_eval = val;
e->best_from_pos = e->current_pos;
e->best_to_pos = to_pos;
}
}
|
/* assumes, that current_pos contains the source position */
|
assumes, that current_pos contains the source position
|
cu_gpos2bpos
|
static uint8_t cu_gpos2bpos(uint8_t gpos)
{
uint8_t bpos = gpos;
bpos &= 0xf0;
bpos >>= 1;
gpos &= 0x0f;
bpos |= gpos;
return bpos;
}
|
/*
gpos: game position value
returns: board position
note: does not do any checks
*/
|
gpos: game position value returns: board position note: does not do any checks
|
cp_Construct
|
static uint8_t cp_Construct(uint8_t color, uint8_t piece)
{
color <<= 4;
color |= piece;
return color;
}
|
/*
piece: one of PIECE_xxx
color: COLOR_WHITE or COLOR_BLACK
returns: A colored piece
*/
|
piece: one of PIECE_xxx color: COLOR_WHITE or COLOR_BLACK
returns: A colored piece
|
cp_GetPiece
|
static uint8_t cp_GetPiece(uint8_t cp)
{
cp &= 0x0f;
return cp;
}
|
/* inline is better than a macro */
|
inline is better than a macro
|
cp_GetColor
|
static uint8_t cp_GetColor(uint8_t cp)
{
cp >>= 4;
cp &= 1;
return cp;
}
|
/*
we could use a macro:
#define cp_GetColor(cp) (((cp) >> 4)&1)
however, inlined functions are sometimes much better
*/
|
we could use a macro: #define cp_GetColor(cp) (((cp) >> 4)&1) however, inlined functions are sometimes much better
|
cp_GetFromBoard
|
uint8_t cp_GetFromBoard(uint8_t pos)
{
return lrc_obj.board[cu_gpos2bpos(pos)];
}
|
/*
pos: game position
returns the colored piece at the given position
*/
|
pos: game position returns the colored piece at the given position
|
cp_SetOnBoard
|
void cp_SetOnBoard(uint8_t pos, uint8_t cp)
{
/*printf("cp_SetOnBoard gpos:%02x cp:%02x\n", pos, cp);*/
lrc_obj.board[cu_gpos2bpos(pos)] = cp;
}
|
/*
pos: game position
cp: colored piece
*/
|
pos: game position cp: colored piece
|
chess_SetupBoardTest01
|
void chess_SetupBoardTest01(void)
{
cu_ClearBoard();
lrc_obj.board[7+7*8] = cp_Construct(COLOR_BLACK, PIECE_KING);
lrc_obj.board[7+5*8] = cp_Construct(COLOR_WHITE, PIECE_PAWN);
lrc_obj.board[3] = cp_Construct(COLOR_WHITE, PIECE_KING);
lrc_obj.board[0+7*8] = cp_Construct(COLOR_BLACK, PIECE_ROOK);
lrc_obj.board[6] = cp_Construct(COLOR_WHITE, PIECE_QUEEN);
}
|
/*
test setup
white wins in one move
*/
|
test setup white wins in one move
|
cu_IsIllegalPosition
|
uint8_t cu_IsIllegalPosition(uint8_t pos, uint8_t my_color)
{
uint8_t board_cp;
/* check, if the position is offboard */
if ( gpos_IsIllegal(pos) != 0 )
return 1;
/* get the piece from the board */
board_cp = cp_GetFromBoard(pos);
/* check if hit our own pieces */
if ( board_cp != 0 )
if ( cp_GetColor(board_cp) == my_color )
return 1;
/* all ok, we could go to this position */
return 0;
}
|
/*
checks if the position is somehow illegal
*/
|
checks if the position is somehow illegal
|
cu_ClearMoveHistory
|
void cu_ClearMoveHistory(void)
{
lrc_obj.chm_pos = 0;
}
|
/* but for an embedded controler... it is deleted for every engine search */
|
but for an embedded controler... it is deleted for every engine search
|
chess_ClearMarks
|
void chess_ClearMarks(void)
{
uint8_t i;
for( i = 0; i < 64; i++ )
lrc_obj.board[i] &= ~CP_MARK_MASK;
}
|
/* clear any marks on the board */
|
clear any marks on the board
|
chess_MarkMovable
|
void chess_MarkMovable(void)
{
stack_Init(0);
//stack_GetCurrElement()->current_color = color;
lrc_obj.check_mode = CHECK_MODE_MOVEABLE;
ce_LoopPieces();
}
|
/*
Mark all pieces which can do moves. This is done by setting flags on the global board
*/
|
Mark all pieces which can do moves. This is done by setting flags on the global board
|
chess_ComputerMove
|
void chess_ComputerMove(uint8_t depth)
{
stack_Init(depth);
//stack_GetCurrElement()->current_color = lrc_obj.ply_count;
//stack_GetCurrElement()->current_color &= 1;
cu_ReduceHistoryByFullMove();
ce_LoopPieces();
chess_ManualMove(stack_GetCurrElement()->best_from_pos, stack_GetCurrElement()->best_to_pos);
}
|
/* let the computer do a move */
|
let the computer do a move
|
init_text
|
void init_text(const char *s)
{
u8g2_uint_t i;
str_len = strlen(s); // calculate number of chars
if ( str_len > MAX_CHARS ) // restrict the no of chars to the size of the offset table
str_len = MAX_CHARS;
char_offset[0] = 0; // start with 0
for( i = 0; i < str_len; i++ )
{
char_offset[i+1] = char_offset[i];
char_offset[i+1] += u8g2_GetGlyphWidth(&u8g2, s[i]); // assume s[i] is the glyph encoding --> no UTF8 support
}
curr_index = 0;
curr_offset = 0;
}
|
/* UTF8 is not supported for "s" */
|
UTF8 is not supported for "s"
|
ugl_bytecode_buildin_procedure
|
void ugl_bytecode_buildin_procedure(const char *name, int idx, int is_toplevel)
{
ugl_plog("BC %scall buildin '%s'", is_toplevel?"toplevel ":"", name);
if ( is_toplevel == 0 )
{
ugl_AddBytecode(BC_CMD_CALL_BUILDIN | ((idx&0x0f00)>>4));
ugl_AddBytecode(idx&0xff);
}
else
{
ugl_AddBytecode(BC_CMD_CALL_BUILDIN_POP_STACK | ((idx&0x0f00)>>4));
ugl_AddBytecode(idx&0xff);
}
}
|
/* code generator sub procedures */
|
code generator sub procedures
|
uglReadLine
|
int uglReadLine(const char **s)
{
ugl_read_line(s);
if ( ugl_indent_level == 0 )
return 0;
return 1;
}
|
/* returns 0 if "endproc" is found */
|
returns 0 if "endproc" is found
|
moveAllItems
|
void moveAllItems(void)
{
uint8_t i;
item_t *item;
i = item_cnt;
item = item_pool;
do
{
posStep(&(item->pos), item->dir);
item->dir = 4; /* no move */
item++;
i--;
} while( i != 0);
}
|
/*
Based on the dir attribute, all items, including hero are moved
*/
|
Based on the dir attribute, all items, including hero are moved
|
getMapTile
|
uint8_t getMapTile(uint8_t x, uint8_t y)
{
item_t *item;
uint16_t offset;
uint8_t i, cnt;
cnt = item_cnt;
for( i = 0; i < cnt; i++ )
{
item = pool_GetItem(i);
if ( item->pos.x == x && item->pos.y == y )
{
return item->tile;
item_under_pos = item;
}
}
item_under_pos = NULL;
offset = y;
offset *= map_list[current_level].width;
offset += x;
return map_list[current_level].data[offset];
}
|
/*
return a tile on the map.
as a side effect,
item_under_pos
is set if the tile is from an item. Otherwise item_under_pos is set to NULL
*/
|
return a tile on the map. as a side effect, item_under_pos is set if the tile is from an item. Otherwise item_under_pos is set to NULL
|
getMapTileByPos
|
uint8_t getMapTileByPos(pos_t *pos)
{
return getMapTile(pos->x, pos->y);
}
|
/*
sideeffect: will set item_under_pos
*/
|
sideeffect: will set item_under_pos
|
isSolidTile
|
uint8_t isSolidTile(uint8_t tile)
{
if ( tile >= 0x07d && tile <= 0x088 )
return 1;
return 0;
}
|
/*
Check whether a tile is solid by definition.
The case, when hitting a tile and it became wakable (because it disapears
or moves away) is not considered.
*/
|
Check whether a tile is solid by definition. The case, when hitting a tile and it became wakable (because it disapears or moves away) is not considered.
|
canWalkTo
|
uint8_t canWalkTo(pos_t *pos)
{
uint8_t tile;
tile = getMapTileByPos(pos);
/*
if ( item_under_pos != NULL )
...
*/
if ( isSolidTile(tile) != 0 )
return 0;
return 1;
}
|
/*
sideeffect: will set item_under_pos
*/
|
sideeffect: will set item_under_pos
|
moveItem
|
uint8_t moveItem(uint8_t item_index, uint8_t dir)
{
item_t *item;
pos_t pos;
item = pool_GetItem(item_index);
pos = item->pos;
posStep(&pos, dir);
if ( canWalkTo(&pos) != 0 )
{
item->dir = dir;
return 1;
}
return 0;
}
|
/*
0: not moved
1: moved
sideeffect: will set item_under_pos
*/
|
0: not moved 1: moved sideeffect: will set item_under_pos
|
bc_get_stack_frame_address
|
uint16_t *bc_get_stack_frame_address(bc_t *bc, uint8_t pos)
{
return bc->arg_stack + bc->return_stack[bc->return_stack_pointer-1] + pos ;
}
|
/* pos = 0 is the return value of a user function, pos = 1... are the args for that function */
|
pos = 0 is the return value of a user function, pos = 1... are the args for that function
|
bc_fn_return
|
void bc_fn_return(bc_t *bc)
{
bc_duplicate_arg_stack_top_value(bc); /* goal is to leave a value on the stack */
*bc_get_stack_frame_address(bc, 0) = bc_pop_from_arg_stack(bc);
/*
v = bc_pop_from_arg_stack(bc);
bc_push_on_arg_stack(bc, v);
bc_pop_from_return_stack(bc);
bc_push_on_return_stack(bc, v);
*/
}
|
/* identical to arg(0) */
|
identical to arg(0)
|
bc_fn_arg1
|
void bc_fn_arg1(bc_t *bc)
{
bc_push_on_arg_stack(bc, *bc_get_stack_frame_address(bc, bc_pop_from_arg_stack(bc)));
}
|
/* return an argument of a user defined procedure */
|
return an argument of a user defined procedure
|
bc_fn_arg2
|
void bc_fn_arg2(bc_t *bc)
{
uint16_t v = bc_pop_from_arg_stack(bc); /* the value, which should be assigned */
*bc_get_stack_frame_address(bc, bc_pop_from_arg_stack(bc)) = v;
bc_push_on_arg_stack(bc, v); /* push the value back on the stack */
}
|
/* remove the top element from the stack and return the same */
|
remove the top element from the stack and return the same
|
i2c_init
|
void i2c_init(void)
{
/* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */
TWSR = 0; /* no prescaler */
TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */
}/* i2c_init */
|
/*************************************************************************
Initialization of the I2C bus interface. Need to be called only once
*************************************************************************/
|
Initialization of the I2C bus interface. Need to be called only once
|
i2c_stop
|
void i2c_stop(void)
{
uint32_t i2c_timer = 0;
/* send stop condition */
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
// wait until stop condition is executed and bus released
i2c_timer = I2C_TIMER_DELAY;
while((TWCR & (1<<TWSTO)) && i2c_timer--);
}/* i2c_stop */
|
/*************************************************************************
Terminates the data transfer and releases the I2C bus
*************************************************************************/
|
Terminates the data transfer and releases the I2C bus
|
i2c_write
|
unsigned char i2c_write( unsigned char data )
{
uint32_t i2c_timer = 0;
uint8_t twst;
// send data to the previously addressed device
TWDR = data;
TWCR = (1<<TWINT) | (1<<TWEN);
// wait until transmission completed
i2c_timer = I2C_TIMER_DELAY;
while(!(TWCR & (1<<TWINT)) && i2c_timer--);
if(i2c_timer == 0)
return 1;
// check value of TWI Status Register. Mask prescaler bits
twst = TW_STATUS & 0xF8;
if( twst != TW_MT_DATA_ACK) return 1;
return 0;
}/* i2c_write */
|
/*************************************************************************
Send one byte to I2C device
Input: byte to be transfered
Return: 0 write successful
1 write failed
*************************************************************************/
|
Send one byte to I2C device
Input: byte to be transfered Return: 0 write successful 1 write failed
|
i2c_readAck
|
unsigned char i2c_readAck(void)
{
uint32_t i2c_timer = 0;
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
i2c_timer = I2C_TIMER_DELAY;
while(!(TWCR & (1<<TWINT)) && i2c_timer--);
if(i2c_timer == 0)
return 0;
return TWDR;
}/* i2c_readAck */
|
/*************************************************************************
Read one byte from the I2C device, request more data from device
Return: byte read from I2C device
*************************************************************************/
|
Read one byte from the I2C device, request more data from device
Return: byte read from I2C device
|
i2c_readNak
|
unsigned char i2c_readNak(void)
{
uint32_t i2c_timer = 0;
TWCR = (1<<TWINT) | (1<<TWEN);
i2c_timer = I2C_TIMER_DELAY;
while(!(TWCR & (1<<TWINT)) && i2c_timer--);
if(i2c_timer == 0)
return 0;
return TWDR;
}/* i2c_readNak */
|
/*************************************************************************
Read one byte from the I2C device, read is followed by a stop condition
Return: byte read from I2C device
*************************************************************************/
|
Read one byte from the I2C device, read is followed by a stop condition
Return: byte read from I2C device
|
placed_box_push
|
pbox_t *placed_box_push(pos_t *p, int box_idx)
{
assert(placed_box_cnt < PLACED_BOX_MAX);
// place the new box
placed_box_list[placed_box_cnt].pos = *p;
placed_box_list[placed_box_cnt].box_idx = box_idx;
placed_box_cnt++;
return placed_box_list+placed_box_cnt-1;
}
|
/* p is copyied, b only the address is stored*/
|
p is copyied, b only the address is stored
|
file_copy
|
int file_copy(const char *source_file_name, const char *dest_file_name)
{
int ch;
FILE *source_fp;
FILE *dest_fp;
source_fp = fopen(source_file_name, "r");
dest_fp = fopen(dest_file_name, "w");
if ( source_fp == NULL || dest_fp == NULL )
return 0;
while( ( ch = fgetc(source_fp) ) != EOF )
fputc(ch, dest_fp);
fclose(source_fp);
fclose(dest_fp);
return 1;
}
|
/*
copy file from source_file_name to dest_file_name
*/
|
copy file from source_file_name to dest_file_name
|
bf_WriteU8G2CByFilename
|
int bf_WriteU8G2CByFilename(bf_t *bf, const char *filename, const char *fontname, const char *indent)
{
FILE *fp;
fp = fopen(filename, "wb");
if ( fp == NULL )
{
bf_Log(bf, "bf_WriteU8G2CByFilename: Open error '%s'", filename);
return 0;
}
bf_WriteU8G2CByFP(bf, fp, fontname, indent);
bf_Log(bf, "bf_WriteU8G2CByFilename: Write file '%s'", filename);
fclose(fp);
return 1;
}
|
/* called from main() */
|
called from main()
|
bdf_is_glyph_overlap
|
static int bdf_is_glyph_overlap(uint8_t *font, uint16_t e1, uint16_t e2, uint8_t kerning_test, int is_save)
{
unsigned int x, y;
tga_clear();
x = 8;
y = tga_get_char_height();
x += tga_draw_glyph(x, y, e1, 0);
x -= kerning_test;
tga_clear_pixel_intersection();
x += tga_draw_glyph(x, y, e2, 0);
if ( is_save )
{
//char buf[64];
//sprintf(buf, "glyph_intersection_%u_%u_%u.tga", e1, e2, kerning_test);
//tga_save(buf);
}
return tga_is_pixel_intersection();
}
|
/*
assumes
tga_set_font(font);
and
tga_init((tga_get_char_width()+16)*3, ((tga_get_char_height()+8)*2));
is called before
*/
|
assumes tga_set_font(font); and tga_init((tga_get_char_width()+16)*3, ((tga_get_char_height()+8)*2)); is called before
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.