aboutsummaryrefslogtreecommitdiff
path: root/style.md
blob: 3347e60e95f7e803cece363cf08288dc9cf6a6dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# code style

this is a quick run-down of basic code style guidelines. code is expected to be
formatted when a pull request is submitted.

## general rules

### style

all of these can automatically be corrected using `make format`

- indent using tab
- tab display width (should) be equal to 2 spaces
- symbols in snake case
- file names in snake case
- c++ classes are in CamelCase
- open brackets on same line

### naming

most (but not all) naming convention errors can be corrected using `make
format` too, but might cause incompatibility issues. make sure to commit code
before formatting as a failsafe.

- prefix symbols with `hh_` (e.g. `hh_game_loop_main`)
- prefix global variables with `g_hh_` (e.g. `g_hh_example_global_variable`)
- global constants are uppercase snake (e.g. `HH_SERIAL_BAUD`)
- enum typedefs are prefixed with `hh_e_` (e.g. `hh_e_entity_state`)
- struct typedefs are prefixed with `hh_s_` (e.g. `hh_s_bam_tile`)
- custom typedefs are prefixed with `hh_` and suffixed with `_t` (e.g. `hh_bam_tile_t`)
- library hooks that need specific symbol names are exempt from the naming
  conventions (e.g. `main` or `HAL_UART_MspInit`)

## others

- document **how to use** code using doxygen-style comments in headers
- document **what code is doing** using inline comments (where applicable)
- don't write redundant comments (e.g. `int c = a + b; // add a and b`)

### markdown

- indent using spaces, align to text start

### vhdl

- vivado puts new files in subfolders, all files (source files, constraints,
  etc.) should be directly in the basys3/basys3.srcs/ folder
- use snake case for naming components
- use uppercase snake case for naming signals and I/O lines
- use lower case keywords