1
0
mirror of https://github.com/kalymos/PsNee.git synced 2026-01-11 23:53:07 +00:00

Refactor comments for clarity in MUC.h

This commit is contained in:
kalymos 2025-12-07 13:00:15 +01:00 committed by GitHub
parent 1a6ad3622a
commit 0fc7d028a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,7 +13,12 @@
//******************************************************************************************************************
//******************************************************************************************************************
// Example: DDRB &= ~(1<<DDB0); // Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0), and then inverting it.
// Example: DDRB &= ~(1<<DDB0);
// Define the pins as inputs.
// Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0), and then inverting it.
// The bitwise AND operation (&=) updates the register DDRB by clearing the DDB0 bit (setting it to 0)
// without affecting the other bits.
//
@ -26,7 +31,12 @@
//******************************************************************************************************************
//******************************************************************************************************************
// Example: DDRB |= (1<<DDB0); // Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0),
// Example: DDRB |= (1<<DDB0);
// Enable pull-ups and set high on the pins.
// Create a mask by shifting the bit 1 to the left by DDB0's position (bit 0),
// and then apply a bitwise OR operation to set DDB0 to 1 (configure pin PB0 as an output).
//
// For instance, if DDRB = b11111111 (binary value), the operation shifts the bit 1 to the left to create the mask
@ -38,7 +48,12 @@
//******************************************************************************************************************
//******************************************************************************************************************
// Example: (PIND & (1<<PIND6)); // Create a mask by shifting the bit 1 to the left by PIND6's position (bit 6),
// Example: (PIND & (1<<PIND6));
// Read the state of the input pins Equivalent.
// Create a mask by shifting the bit 1 to the left by PIND6's position (bit 6),
// and then apply a bitwise AND operation to read the state of the PIND6 pin.
// The result will be non-zero (true) if the PIND6 pin is high (1), and zero (false) if the PIND6 pin is low (0).
//
@ -52,8 +67,49 @@
//
//******************************************************************************************************************
//******************************************************************************************************************
// Example: PORTB |= (1<<PB0);
// Set the state of an output pin to HIGH (Equivalent of Arduino digitalWrite(8, HIGH);).
// Create a mask by shifting the bit 1 to the left by PB0's position (bit 0),
// and then apply a bitwise OR operation to force the PB0 pin to a high state.
// This operation modifies only the target bit without affecting the others in the register.
//
// For instance, if PORTB = b10101010 (binary value), the operation shifts the bit 1 to the left to create the mask
// (1<<PB0) = b00000001. The OR operation between PORTB and the mask ensures the 0th bit becomes 1 (high).
//
// Before: PORTB = b10101010 // Initial value of PORTB (register controlling output pin states)
// Mask: (1<<PB0) = b00000001 // Mask generated by shifting the bit 1 to the left to position PB0
// Operation: PORTB | b00000001 = b10101011 // The 0th bit is set to 1 (high)
//
//******************************************************************************************************************
//******************************************************************************************************************
// Example: PORTB &= ~(1<<PB0);
// Set the state of an output pin to LOW (Equivalent of Arduino digitalWrite(8, LOW);).
// Create a mask by shifting the bit 1 to the left by PB0's position (bit 0).
// The mask is then inverted at the bit level (binary NOT) to create a clearing mask (all bits are 1 except the target bit, which is 0).
// Finally, a bitwise AND operation is applied to force the PB0 pin to a low state.
// This operation modifies only the target bit without affecting the others in the register.
//
// For instance, if PORTB = b10101011 (binary value), the generated mask is (1<<PB0) = b00000001.
// Inverting (NOT) the mask yields ~(1<<PB0) = b11111110.
// The bitwise AND operation between PORTB and the clearing mask ensures the 0th bit becomes 0 (low).
//
// Before: PORTB = b10101011 // Initial value of PORTB (register controlling output pin states)
// Mask: ~(1<<PB0) = b11111110 // Generated clearing mask
// Operation: PORTB & b11111110 = b10101010 // The 0th bit is set to 0 (low)
//
//******************************************************************************************************************
//******************************************************************************************************************
// Example: EICRA |= (1<<ISC01) | (1<<ISC00);
// This operation configures the external interrupt sense control (ISC) for interrupt INT0 (External Interrupt Request 0).
// Specifically, it sets the mode of INT0 to "rising edge" trigger, meaning the interrupt will be triggered when the pin
// transitions from low to high (rising edge).
@ -73,6 +129,7 @@
//******************************************************************************************************************
// Example: EICRA = (EICRA & ~(1<<ISC00)) | (1<<ISC01);
// This operation configures the external interrupt sense control (ISC) for interrupt INT0 (External Interrupt Request 0).
// Specifically, it sets INT0 to trigger on a "falling edge" (when the signal transitions from high to low).
//
@ -125,24 +182,24 @@
// Main pin configuration for input and output
// Define the main pins as inputs
// Define the main pins as inputs. Equivalent Arduino code: pinMode(x, INPUT));
#define PIN_DATA_INPUT DDRB &= ~(1<<DDB0) // Set DDRB register to configure PINB0 as input
#define PIN_WFCK_INPUT DDRB &= ~(1<<DDB1) // Set DDRB register to configure PINB1 as input
#define PIN_SQCK_INPUT DDRD &= ~(1<<DDD6) // Set DDRB register to configure PINB6 as input
#define PIN_SUBQ_INPUT DDRD &= ~(1<<DDD7) // Set DDRB register to configure PINB7 as input
// Enable pull-ups and set high on the main pins
// Enable pull-ups and set high on the main pins. Equivalent Arduino code: pinMode(x, OUTPUT);
#define PIN_DATA_OUTPUT DDRB |= (1<<DDB0) // Set DDRB register to configure PINB0 as output
#define PIN_WFCK_OUTPUT DDRB |= (1<<DDB1) // Set DDRB register to configure PINB1 as output
// Define pull-ups and set high at the main pin
// Define pull-ups and set high at the main pin. Equivalent Arduino code: digitalWrite(x, HIGH);
#define PIN_DATA_SET PORTB |= (1<<PB0) // Set PORTB register to make PINB0 high (enable pull-up)
// Clear the main pins (set low)
// Clear the main pins (set low). Equivalent Arduino code: digitalWrite(x, LOW);
#define PIN_DATA_CLEAR PORTB &= ~(1<<PB0) // Set PORTB register to make PINB0 low
#define PIN_WFCK_CLEAR PORTB &= ~(1<<PB1) // Set PORTB register to make PINB1 low
// Read the state of the main input pins
// Read the state of the main input pins Equivalent. Arduino code: (digitalRead(x) == HIGH)
#define PIN_SQCK_READ (PIND & (1<<PIND6)) // Check if the value of PIND6 is high (1)
#define PIN_SUBQ_READ (PIND & (1<<PIND7)) // Check if the value of PIND7 is high (1)
#define PIN_WFCK_READ (PINB & (1<<PINB1)) // Check if the value of PIND1 is high (1)