Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

86 строки
3.4 KiB

  1. ------------------------------------------------------------------------------
  2. HACKING
  3. ------------------------------------------------------------------------------
  4. Coding style
  5. ------------
  6. The whole library is programmed using the Linux kernel coding style, see
  7. https://www.kernel.org/doc/html/latest/process/coding-style.html for details.
  8. Please use the same style for any code contributions, thanks!
  9. Amendments to the Linux kernel coding style
  10. -------------------------------------------
  11. 1) We use the stdint types. The linux kernel accepts the abbreviated types (u8,
  12. s8, u16 and so on) for legacy reasons. We should in general not introduce
  13. things like types ourselves as long as they are not necessary to make our
  14. job possible of refining the hardware and make it easier to be used. stdint
  15. is a standard and it is not in the scope of our project to introduce a new
  16. type standard.
  17. 2) Based on the same logic as in (1) we do not use __packed and __aligned
  18. definitions, it is not our job to add compiler extensions. If we need to
  19. deal with compiler incompatibility we will do that the same way we are
  20. dealing with the deprecated attribute by introducing a normal macro that is
  21. not in the compiler reserved keyword space.
  22. 3) We accept to write an empty body busy waiting while loop like this:
  23. while (1);
  24. there is no need to put the colon on the next line as per linux kernel
  25. style.
  26. 4) We always add brackets around bodies of if, while and for statements, even
  27. if the body contains only one expression. It is dangerous to not have them
  28. as it easily happens that one adds a second expression and is hunting for
  29. hours why the code is not working just because of a missing bracket pair.
  30. Development guidelines
  31. ----------------------
  32. - Every new file added must have the usual license header, see the
  33. existing files for examples.
  34. - In general, please try to keep the register and bit naming as close
  35. as possible to the official vendor datasheets. Among other reasons, this
  36. makes it easier for users to find what they're looking for in the
  37. datasheets, programming manuals, and application notes.
  38. - All register definitions should follow the following naming conventions:
  39. - The #define names should be all-caps, parts are separated by
  40. an underscore.
  41. - The name should be of the form SUBSYSTEM_REGISTER_BIT, e.g.
  42. ADC_CR2_DMA, where ADC is the subsystem name, CR2 is the register NAME,
  43. and DMA is the name of the bit in the register that is defined.
  44. - All subsystem-specific function names should be prefixed with the
  45. subsystem name. For example, gpio_set_mode() or rcc_osc_on().
  46. - Please consistently use the stdint types.
  47. - Variables that are used to store register values read from registers or
  48. to be stored in a register should be named reg8, reg16, reg32 etc.
  49. - For examples on using libopencm3 see the libopencm3-examples repository.
  50. - Doxygen is used to generate API docs, please follow that style for function
  51. and definition commentary where possible.
  52. Tips and tricks
  53. ---------------
  54. SublimeText users:
  55. - The project contains a sublime project description file with some basic
  56. settings provided to make hacking on libopencm3 easier.
  57. - Recommended SublimeText plugins when hacking on libopencm3:
  58. - TrailingSpaces: Show and trim trailing line spaces.
  59. - SublimeLinter: Run checkpatch.pl in the background while you write your
  60. code and indicate possible coding style issues on the fly.