lv_conf_internal_gen.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/usr/bin/env python3
  2. '''
  3. Generates lv_conf_internal.h from lv_conf_template.h to provide default values
  4. '''
  5. import os
  6. import sys
  7. import re
  8. SCRIPT_DIR = os.path.dirname(__file__)
  9. LV_CONF_TEMPLATE = os.path.join(SCRIPT_DIR, "..", "lv_conf_template.h")
  10. LV_CONF_INTERNAL = os.path.join(SCRIPT_DIR, "..", "src", "lv_conf_internal.h")
  11. if sys.version_info < (3,6,0):
  12. print("Python >=3.6 is required", file=sys.stderr)
  13. exit(1)
  14. fin = open(LV_CONF_TEMPLATE)
  15. fout = open(LV_CONF_INTERNAL, "w")
  16. fout.write(
  17. '''/**
  18. * GENERATED FILE, DO NOT EDIT IT!
  19. * @file lv_conf_internal.h
  20. * Make sure all the defines of lv_conf.h have a default value
  21. **/
  22. #ifndef LV_CONF_INTERNAL_H
  23. #define LV_CONF_INTERNAL_H
  24. /* clang-format off */
  25. #include <stdint.h>
  26. /* Handle special Kconfig options */
  27. #ifndef LV_KCONFIG_IGNORE
  28. #include "lv_conf_kconfig.h"
  29. #ifdef CONFIG_LV_CONF_SKIP
  30. #define LV_CONF_SKIP
  31. #endif
  32. #endif
  33. /*If "lv_conf.h" is available from here try to use it later.*/
  34. #ifdef __has_include
  35. #if __has_include("lv_conf.h")
  36. #ifndef LV_CONF_INCLUDE_SIMPLE
  37. #define LV_CONF_INCLUDE_SIMPLE
  38. #endif
  39. #endif
  40. #endif
  41. /*If lv_conf.h is not skipped include it*/
  42. #ifndef LV_CONF_SKIP
  43. #ifdef LV_CONF_PATH /*If there is a path defined for lv_conf.h use it*/
  44. #define __LV_TO_STR_AUX(x) #x
  45. #define __LV_TO_STR(x) __LV_TO_STR_AUX(x)
  46. #include __LV_TO_STR(LV_CONF_PATH)
  47. #undef __LV_TO_STR_AUX
  48. #undef __LV_TO_STR
  49. #elif defined(LV_CONF_INCLUDE_SIMPLE) /*Or simply include lv_conf.h is enabled*/
  50. #include "lv_conf.h"
  51. #else
  52. #include "../../lv_conf.h" /*Else assume lv_conf.h is next to the lvgl folder*/
  53. #endif
  54. #if !defined(LV_CONF_H) && !defined(LV_CONF_SUPPRESS_DEFINE_CHECK)
  55. /* #include will sometimes silently fail when __has_include is used */
  56. /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80753 */
  57. #pragma message("Possible failure to include lv_conf.h, please read the comment in this file if you get errors")
  58. #endif
  59. #endif
  60. #ifdef CONFIG_LV_COLOR_DEPTH
  61. #define _LV_KCONFIG_PRESENT
  62. #endif
  63. /*----------------------------------
  64. * Start parsing lv_conf_template.h
  65. -----------------------------------*/
  66. '''
  67. )
  68. started = 0
  69. for line in fin.read().splitlines():
  70. if not started:
  71. if '#define LV_CONF_H' in line:
  72. started = 1
  73. continue
  74. else:
  75. continue
  76. if '/*--END OF LV_CONF_H--*/' in line: break
  77. #Is there a #define in this line?
  78. r = re.search(r'^([\s]*)#[\s]*(undef|define)[\s]+([^\s]+).*$', line) # \s means any white space character
  79. if r:
  80. indent = r[1]
  81. name = r[3]
  82. name = re.sub('\(.*?\)', '', name, 1) #remove parentheses from macros. E.g. MY_FUNC(5) -> MY_FUNC
  83. line = re.sub('[\s]*', '', line, 1)
  84. #If the value should be 1 (enabled) by default use a more complex structure for Kconfig checks because
  85. #if a not defined CONFIG_... value should be interpreted as 0 and not the LVGL default
  86. is_one = re.search(r'#[\s]*define[\s]*[A-Z0-9_]+[\s]+1([\s]*$|[\s]+)', line)
  87. if is_one:
  88. #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing)
  89. #2. In Kconfig environment use the CONFIG_... value if set, else use 0
  90. #3. In not Kconfig environment use the LVGL's default value
  91. fout.write(
  92. f'{indent}#ifndef {name}\n'
  93. f'{indent} #ifdef _LV_KCONFIG_PRESENT\n'
  94. f'{indent} #ifdef CONFIG_{name.upper()}\n'
  95. f'{indent} #define {name} CONFIG_{name.upper()}\n'
  96. f'{indent} #else\n'
  97. f'{indent} #define {name} 0\n'
  98. f'{indent} #endif\n'
  99. f'{indent} #else\n'
  100. f'{indent} {line}\n'
  101. f'{indent} #endif\n'
  102. f'{indent}#endif\n'
  103. )
  104. else:
  105. #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing)
  106. #2. Use the Kconfig value if set
  107. #3. Use the LVGL's default value
  108. fout.write(
  109. f'{indent}#ifndef {name}\n'
  110. f'{indent} #ifdef CONFIG_{name.upper()}\n'
  111. f'{indent} #define {name} CONFIG_{name.upper()}\n'
  112. f'{indent} #else\n'
  113. f'{indent} {line}\n'
  114. f'{indent} #endif\n'
  115. f'{indent}#endif\n'
  116. )
  117. elif re.search('^ *typedef .*;.*$', line):
  118. continue #ignore typedefs to avoid redeclaration
  119. else:
  120. fout.write(f'{line}\n')
  121. fout.write(
  122. '''
  123. /*----------------------------------
  124. * End of parsing lv_conf_template.h
  125. -----------------------------------*/
  126. LV_EXPORT_CONST_INT(LV_DPI_DEF);
  127. #undef _LV_KCONFIG_PRESENT
  128. /*Set some defines if a dependency is disabled*/
  129. #if LV_USE_LOG == 0
  130. #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE
  131. #define LV_LOG_TRACE_MEM 0
  132. #define LV_LOG_TRACE_TIMER 0
  133. #define LV_LOG_TRACE_INDEV 0
  134. #define LV_LOG_TRACE_DISP_REFR 0
  135. #define LV_LOG_TRACE_EVENT 0
  136. #define LV_LOG_TRACE_OBJ_CREATE 0
  137. #define LV_LOG_TRACE_LAYOUT 0
  138. #define LV_LOG_TRACE_ANIM 0
  139. #endif /*LV_USE_LOG*/
  140. /*If running without lv_conf.h add typedefs with default value*/
  141. #ifdef LV_CONF_SKIP
  142. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/
  143. #define _CRT_SECURE_NO_WARNINGS
  144. #endif
  145. #endif /*defined(LV_CONF_SKIP)*/
  146. #endif /*LV_CONF_INTERNAL_H*/
  147. '''
  148. )
  149. fin.close()
  150. fout.close()