Skip to content
hasu@tmk edited this page Nov 19, 2021 · 28 revisions

Integer Overflow/Rollover

https://arduino.stackexchange.com/a/12588

Arduino Timer:

  • unsigned long millis()
  • unsigned long micros()

unsigned long is 32-bit size on AVR. millis() rollovers in 49.7 days and micros() in 71.58 secs.

C Integer

Integer Promotion

With the exception of a few special cases like ++ and sizeof operators, the integer promotions apply to almost all operations in C, no matter if unary, binary (or ternary) operators are used.

C11 6.3.1.1:

If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.

The integer promotions are applied only: as part of the usual arithmetic conversions, to certain argument expressions, to the operands of the unary +, -, and ~ operators, and to both operands of the shift operators, as specified by their respective subclauses.

https://port70.net/~nsz/c/c11/n1570.html#6.3.1.1

Usual arithmetic conversions

Whenever a binary operation (an operation with 2 operands) is done in C, both operands of the operator have to be of the same type. Therefore, in case the operands are of different types, C enforces an implicit conversion of one operand to the type of the other operand. The rules for how this is done are named the usual artihmetic conversions (sometimes informally referred to as "balancing"). These are specified in C11 6.3.18:

Notable here is that the usual arithmetic conversions apply to both floating point and integer variables. In case of integers, we can also note that the integer promotions are invoked from within the usual arithmetic conversions. And after that, when both operands have at least the rank of int, the operators are balanced to the same type, with the same signedness.

C11 6.3.1.8 Usual arithmetic conversions

  • Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands:
    • If both operands have the same type, then no further conversion is needed.
    • Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
    • Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.
    • Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.
    • Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

https://port70.net/~nsz/c/c11/n1570.html#6.3.1.8

AVR Integer Size

https://gcc.gnu.org/wiki/avr-gcc#Type_Layout

https://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html

IDEA

Minmal firmware Build

for non-keyboard project

  • NO_KEYBOARD build option for minimal build
  • 6KRO_ENABLE(boot keyboard compatible when report protocol)
  • NKRO_ENABLE

currently keyboard function is built automatically without any options.

Mouse Scroll Wheel Emulation

two implementatons exists on PS/2 and ADB. One common impl to be shared by projects would be nice.

IBMPC buffer handling on send

Data on recv buffer can be removed by calling host_send(). TODO: Fix

MOUSE_ENABLE/MOUSEKEY_ENABLE Build Option

need to be organized

MOUSE_ENABLE is needed for mouse project without mouse key feature. It enables mouse output interface.

Control Endpoint 0

Send command to the endpoint for hidden functions.

UHS3

class

UHS_host/UHS_HID/UHS_HID.h

UHS_HID : UHS_USBInterface

  • UHS_HID(UHS_USB_HOST_BASE *p, UHS_HID_PROCESSOR *hp)
  • Start()
  • OKtoEnumerate(ENUMERATION_INFO *ei)
  • SetInterface(ENUMERATION_INFO *ei)
  • Poll()
  • DriverDefaults()
  • driverPoll()
  • GetAddress()
  • Polling()
  • OnRelease()
  • SetIdle(iface, reportID, duration)
  • SetProtocol(iface, protocol)
  • SetReport(iface, report_type, report_id, nbytes, dataptr)
  • ReportDescr(wIndex, nbytes, *buffer)

UHS_HID_PROCESSOR

  • onStart(UHS_HID_base)
  • onPoll(UHS_HID_base, data, length)
  • onRelease(UHS_HID_base)

UHS_HID_base

HID drivers: RAW, KEYBOARD, MOUSE

  • UHS_HID *parent
  • UHS_HID_driver_t driver
  • driverPoll()
  • driverStart()
  • driverRelease()
  • writeReport(nbytes, *dataptr)

UHS_HID_RAW : UHS_HID_base

UHS_host/UHS_HID/HIDBOOT/UHS_HIDRAWBOOT_KEYBOARD.h

UHS_HIDBOOT_keyboard : UHS_HID_base

UHS_host/UHS_HID/HIDBOOT/UHS_HIDRAWBOOT_MOUSE.h

UHS_HIDBOOT_mouse : UHS_HID_base

Clone this wiki locally