Edvin Pap
Edvin Pap

Reputation: 90

How to represent active low variables?

I've found trailing '#' characters in the pin description section in some datasheets, which indicates that the specific pin has active-low functionality.

Is there any conventions for variable names which hold for example pulled up GPIO input pin values?

Upvotes: 1

Views: 1125

Answers (2)

Lundin
Lundin

Reputation: 214525

The common signal naming conventions in datasheets and schematics would be either a \ prefix or a line above the text. Neither can be used in C.

So the most common naming convention I've seen in C is probably a postfix _inv for inverted signals. Or perhaps less commonly using inv_ as prefix.

You might in some cases want to add a bit of abstraction layer to variably switch a GPIO pin from active high to active low in software.

Upvotes: 2

Tom V
Tom V

Reputation: 5510

It is very helpful when translating a schematic to a header file with constants for the pin numbers to name the constants as close as possible to the net names on the schematic.

This leaves three problems that I have encountered regularly:

  1. Net names with a dash: I just replace this with an underscore. BAT-LEVEL becomes BAT_LEVEL.

  2. Net names starting with a digit: I start all the pin numbers with the same prefix: 3V3_ENABLE becomes PIN_3V3_ENABLE.

  3. Net names with a slash or hash character or overbar (all of which signify active low). I replace this with a lower-case n in an otherwise all-capitals constant. SPI_CS# becomes SPI_nCS.

Upvotes: 3

Related Questions