update to pxt 5 and pxt-common-packages 6 (#934)
* bump pxt * fix build issues * Auto-gen of projects/summary * removing feild editors moved to pxt * various typing fixes * more typing fixes * fixing various typing issues * Start on integration of new pxt * serial number fixes * gc-ify MMap object * Re-build generated files * fix console listeners * clear lf() warnings * More generated files * also auto-generated * Compilation fixes * fix merge * mostly fixing blocks * fix sim * fix field motors * enable a few features * moving to tsx * try to fix edtiro compilation * more defs * removing commands * removing extra $ * fix blockly warning * hiding images * enabling more pxt features * hide images * setup autorun * add lock on target_reset * update deps * return trylock result * updated pxt * rename video section * add alpha channel * upgraded pxt * bump pxt/version * removed alpha ref * var ceanup * don't do major bump
This commit is contained in:
		
				
					committed by
					
						
						Peli de Halleux
					
				
			
			
				
	
			
			
			
						parent
						
							ba94322d4c
						
					
				
				
					commit
					c5cec3a6ba
				
			@@ -1,40 +0,0 @@
 | 
			
		||||
#include "pxt.h"
 | 
			
		||||
 | 
			
		||||
namespace control {
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Announce that an event happened to registered handlers.
 | 
			
		||||
 * @param src ID of the Component that generated the event
 | 
			
		||||
 * @param value Component specific code indicating the cause of the event.
 | 
			
		||||
 * @param mode optional definition of how the event should be processed after construction.
 | 
			
		||||
 */
 | 
			
		||||
//% weight=21 blockGap=12 blockId="control_raise_event"
 | 
			
		||||
//% block="raise event|from %src|with value %value" blockExternalInputs=1
 | 
			
		||||
//% help=control/raise-event
 | 
			
		||||
void raiseEvent(int src, int value) {
 | 
			
		||||
    pxt::raiseEvent(src, value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Allocates the next user notification event
 | 
			
		||||
*/
 | 
			
		||||
//% help=control/allocate-notify-event
 | 
			
		||||
int allocateNotifyEvent() {
 | 
			
		||||
    return pxt::allocateNotifyEvent();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Write data to DMESG debugging buffer. */
 | 
			
		||||
//%
 | 
			
		||||
void dmesg(String s) {
 | 
			
		||||
    DMESG("# %s", s->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace serial {
 | 
			
		||||
    /** Send DMESG debug buffer over serial. */
 | 
			
		||||
    //%
 | 
			
		||||
    void writeDmesg() {
 | 
			
		||||
        pxt::dumpDmesg();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										407
									
								
								libs/core/dal.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										407
									
								
								libs/core/dal.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -1,6 +1,305 @@
 | 
			
		||||
// Auto-generated. Do not edit.
 | 
			
		||||
declare const enum DAL {
 | 
			
		||||
    // built/dockermake/pxtapp/ev3const.h
 | 
			
		||||
    // /pxtapp/configkeys.h
 | 
			
		||||
    CFG_PIN_NAME_MSK = 65535,
 | 
			
		||||
    CFG_PIN_CONFIG_MSK = 4294901760,
 | 
			
		||||
    CFG_PIN_CONFIG_ACTIVE_LO = 65536,
 | 
			
		||||
    CFG_MAGIC0 = 513675505,
 | 
			
		||||
    CFG_MAGIC1 = 539130489,
 | 
			
		||||
    CFG_PIN_ACCELEROMETER_INT = 1,
 | 
			
		||||
    CFG_PIN_ACCELEROMETER_SCL = 2,
 | 
			
		||||
    CFG_PIN_ACCELEROMETER_SDA = 3,
 | 
			
		||||
    CFG_PIN_BTN_A = 4,
 | 
			
		||||
    CFG_PIN_BTN_B = 5,
 | 
			
		||||
    CFG_PIN_BTN_SLIDE = 6,
 | 
			
		||||
    CFG_PIN_DOTSTAR_CLOCK = 7,
 | 
			
		||||
    CFG_PIN_DOTSTAR_DATA = 8,
 | 
			
		||||
    CFG_PIN_FLASH_CS = 9,
 | 
			
		||||
    CFG_PIN_FLASH_MISO = 10,
 | 
			
		||||
    CFG_PIN_FLASH_MOSI = 11,
 | 
			
		||||
    CFG_PIN_FLASH_SCK = 12,
 | 
			
		||||
    CFG_PIN_LED = 13,
 | 
			
		||||
    CFG_PIN_LIGHT = 14,
 | 
			
		||||
    CFG_PIN_MICROPHONE = 15,
 | 
			
		||||
    CFG_PIN_MIC_CLOCK = 16,
 | 
			
		||||
    CFG_PIN_MIC_DATA = 17,
 | 
			
		||||
    CFG_PIN_MISO = 18,
 | 
			
		||||
    CFG_PIN_MOSI = 19,
 | 
			
		||||
    CFG_PIN_NEOPIXEL = 20,
 | 
			
		||||
    CFG_PIN_RX = 21,
 | 
			
		||||
    CFG_PIN_RXLED = 22,
 | 
			
		||||
    CFG_PIN_SCK = 23,
 | 
			
		||||
    CFG_PIN_SCL = 24,
 | 
			
		||||
    CFG_PIN_SDA = 25,
 | 
			
		||||
    CFG_PIN_SPEAKER_AMP = 26,
 | 
			
		||||
    CFG_PIN_TEMPERATURE = 27,
 | 
			
		||||
    CFG_PIN_TX = 28,
 | 
			
		||||
    CFG_PIN_TXLED = 29,
 | 
			
		||||
    CFG_PIN_IR_OUT = 30,
 | 
			
		||||
    CFG_PIN_IR_IN = 31,
 | 
			
		||||
    CFG_PIN_DISPLAY_SCK = 32,
 | 
			
		||||
    CFG_PIN_DISPLAY_MISO = 33,
 | 
			
		||||
    CFG_PIN_DISPLAY_MOSI = 34,
 | 
			
		||||
    CFG_PIN_DISPLAY_CS = 35,
 | 
			
		||||
    CFG_PIN_DISPLAY_DC = 36,
 | 
			
		||||
    CFG_DISPLAY_WIDTH = 37,
 | 
			
		||||
    CFG_DISPLAY_HEIGHT = 38,
 | 
			
		||||
    CFG_DISPLAY_CFG0 = 39,
 | 
			
		||||
    CFG_DISPLAY_CFG1 = 40,
 | 
			
		||||
    CFG_DISPLAY_CFG2 = 41,
 | 
			
		||||
    CFG_DISPLAY_CFG3 = 42,
 | 
			
		||||
    CFG_PIN_DISPLAY_RST = 43,
 | 
			
		||||
    CFG_PIN_DISPLAY_BL = 44,
 | 
			
		||||
    CFG_PIN_SERVO_1 = 45,
 | 
			
		||||
    CFG_PIN_SERVO_2 = 46,
 | 
			
		||||
    CFG_PIN_BTN_LEFT = 47,
 | 
			
		||||
    CFG_PIN_BTN_RIGHT = 48,
 | 
			
		||||
    CFG_PIN_BTN_UP = 49,
 | 
			
		||||
    CFG_PIN_BTN_DOWN = 50,
 | 
			
		||||
    CFG_PIN_BTN_MENU = 51,
 | 
			
		||||
    CFG_PIN_LED_R = 52,
 | 
			
		||||
    CFG_PIN_LED_G = 53,
 | 
			
		||||
    CFG_PIN_LED_B = 54,
 | 
			
		||||
    CFG_PIN_LED1 = 55,
 | 
			
		||||
    CFG_PIN_LED2 = 56,
 | 
			
		||||
    CFG_PIN_LED3 = 57,
 | 
			
		||||
    CFG_PIN_LED4 = 58,
 | 
			
		||||
    CFG_SPEAKER_VOLUME = 59,
 | 
			
		||||
    CFG_PIN_JACK_TX = 60,
 | 
			
		||||
    CFG_PIN_JACK_SENSE = 61,
 | 
			
		||||
    CFG_PIN_JACK_HPEN = 62,
 | 
			
		||||
    CFG_PIN_JACK_BZEN = 63,
 | 
			
		||||
    CFG_PIN_JACK_PWREN = 64,
 | 
			
		||||
    CFG_PIN_JACK_SND = 65,
 | 
			
		||||
    CFG_PIN_JACK_BUSLED = 66,
 | 
			
		||||
    CFG_PIN_JACK_COMMLED = 67,
 | 
			
		||||
    CFG_PIN_BTN_SOFT_RESET = 69,
 | 
			
		||||
    CFG_ACCELEROMETER_TYPE = 70,
 | 
			
		||||
    CFG_PIN_BTNMX_LATCH = 71,
 | 
			
		||||
    CFG_PIN_BTNMX_CLOCK = 72,
 | 
			
		||||
    CFG_PIN_BTNMX_DATA = 73,
 | 
			
		||||
    CFG_PIN_BTN_MENU2 = 74,
 | 
			
		||||
    CFG_PIN_BATTSENSE = 75,
 | 
			
		||||
    CFG_PIN_VIBRATION = 76,
 | 
			
		||||
    CFG_PIN_PWREN = 77,
 | 
			
		||||
    CFG_DISPLAY_TYPE = 78,
 | 
			
		||||
    CFG_PIN_ROTARY_ENCODER_A = 79,
 | 
			
		||||
    CFG_PIN_ROTARY_ENCODER_B = 80,
 | 
			
		||||
    CFG_ACCELEROMETER_SPACE = 81,
 | 
			
		||||
    CFG_PIN_WIFI_MOSI = 82,
 | 
			
		||||
    CFG_PIN_WIFI_MISO = 83,
 | 
			
		||||
    CFG_PIN_WIFI_SCK = 84,
 | 
			
		||||
    CFG_PIN_WIFI_TX = 85,
 | 
			
		||||
    CFG_PIN_WIFI_RX = 86,
 | 
			
		||||
    CFG_PIN_WIFI_CS = 87,
 | 
			
		||||
    CFG_PIN_WIFI_BUSY = 88,
 | 
			
		||||
    CFG_PIN_WIFI_RESET = 89,
 | 
			
		||||
    CFG_PIN_WIFI_GPIO0 = 90,
 | 
			
		||||
    CFG_PIN_WIFI_AT_TX = 91,
 | 
			
		||||
    CFG_PIN_WIFI_AT_RX = 92,
 | 
			
		||||
    CFG_PIN_USB_POWER = 93,
 | 
			
		||||
    ACCELEROMETER_TYPE_LIS3DH = 50,
 | 
			
		||||
    ACCELEROMETER_TYPE_LIS3DH_ALT = 48,
 | 
			
		||||
    ACCELEROMETER_TYPE_MMA8453 = 56,
 | 
			
		||||
    ACCELEROMETER_TYPE_FXOS8700 = 60,
 | 
			
		||||
    ACCELEROMETER_TYPE_MMA8653 = 58,
 | 
			
		||||
    ACCELEROMETER_TYPE_MSA300 = 76,
 | 
			
		||||
    ACCELEROMETER_TYPE_MPU6050 = 104,
 | 
			
		||||
    DISPLAY_TYPE_ST7735 = 7735,
 | 
			
		||||
    DISPLAY_TYPE_ILI9341 = 9341,
 | 
			
		||||
    CFG_PIN_A0 = 100,
 | 
			
		||||
    CFG_PIN_A1 = 101,
 | 
			
		||||
    CFG_PIN_A2 = 102,
 | 
			
		||||
    CFG_PIN_A3 = 103,
 | 
			
		||||
    CFG_PIN_A4 = 104,
 | 
			
		||||
    CFG_PIN_A5 = 105,
 | 
			
		||||
    CFG_PIN_A6 = 106,
 | 
			
		||||
    CFG_PIN_A7 = 107,
 | 
			
		||||
    CFG_PIN_A8 = 108,
 | 
			
		||||
    CFG_PIN_A9 = 109,
 | 
			
		||||
    CFG_PIN_A10 = 110,
 | 
			
		||||
    CFG_PIN_A11 = 111,
 | 
			
		||||
    CFG_PIN_A12 = 112,
 | 
			
		||||
    CFG_PIN_A13 = 113,
 | 
			
		||||
    CFG_PIN_A14 = 114,
 | 
			
		||||
    CFG_PIN_A15 = 115,
 | 
			
		||||
    CFG_PIN_A16 = 116,
 | 
			
		||||
    CFG_PIN_A17 = 117,
 | 
			
		||||
    CFG_PIN_A18 = 118,
 | 
			
		||||
    CFG_PIN_A19 = 119,
 | 
			
		||||
    CFG_PIN_A20 = 120,
 | 
			
		||||
    CFG_PIN_A21 = 121,
 | 
			
		||||
    CFG_PIN_A22 = 122,
 | 
			
		||||
    CFG_PIN_A23 = 123,
 | 
			
		||||
    CFG_PIN_A24 = 124,
 | 
			
		||||
    CFG_PIN_A25 = 125,
 | 
			
		||||
    CFG_PIN_A26 = 126,
 | 
			
		||||
    CFG_PIN_A27 = 127,
 | 
			
		||||
    CFG_PIN_A28 = 128,
 | 
			
		||||
    CFG_PIN_A29 = 129,
 | 
			
		||||
    CFG_PIN_A30 = 130,
 | 
			
		||||
    CFG_PIN_A31 = 131,
 | 
			
		||||
    CFG_PIN_D0 = 150,
 | 
			
		||||
    CFG_PIN_D1 = 151,
 | 
			
		||||
    CFG_PIN_D2 = 152,
 | 
			
		||||
    CFG_PIN_D3 = 153,
 | 
			
		||||
    CFG_PIN_D4 = 154,
 | 
			
		||||
    CFG_PIN_D5 = 155,
 | 
			
		||||
    CFG_PIN_D6 = 156,
 | 
			
		||||
    CFG_PIN_D7 = 157,
 | 
			
		||||
    CFG_PIN_D8 = 158,
 | 
			
		||||
    CFG_PIN_D9 = 159,
 | 
			
		||||
    CFG_PIN_D10 = 160,
 | 
			
		||||
    CFG_PIN_D11 = 161,
 | 
			
		||||
    CFG_PIN_D12 = 162,
 | 
			
		||||
    CFG_PIN_D13 = 163,
 | 
			
		||||
    CFG_PIN_D14 = 164,
 | 
			
		||||
    CFG_PIN_D15 = 165,
 | 
			
		||||
    CFG_PIN_D16 = 166,
 | 
			
		||||
    CFG_PIN_D17 = 167,
 | 
			
		||||
    CFG_PIN_D18 = 168,
 | 
			
		||||
    CFG_PIN_D19 = 169,
 | 
			
		||||
    CFG_PIN_D20 = 170,
 | 
			
		||||
    CFG_PIN_D21 = 171,
 | 
			
		||||
    CFG_PIN_D22 = 172,
 | 
			
		||||
    CFG_PIN_D23 = 173,
 | 
			
		||||
    CFG_PIN_D24 = 174,
 | 
			
		||||
    CFG_PIN_D25 = 175,
 | 
			
		||||
    CFG_PIN_D26 = 176,
 | 
			
		||||
    CFG_PIN_D27 = 177,
 | 
			
		||||
    CFG_PIN_D28 = 178,
 | 
			
		||||
    CFG_PIN_D29 = 179,
 | 
			
		||||
    CFG_PIN_D30 = 180,
 | 
			
		||||
    CFG_PIN_D31 = 181,
 | 
			
		||||
    CFG_NUM_NEOPIXELS = 200,
 | 
			
		||||
    CFG_NUM_DOTSTARS = 201,
 | 
			
		||||
    CFG_DEFAULT_BUTTON_MODE = 202,
 | 
			
		||||
    CFG_SWD_ENABLED = 203,
 | 
			
		||||
    CFG_FLASH_BYTES = 204,
 | 
			
		||||
    CFG_RAM_BYTES = 205,
 | 
			
		||||
    CFG_SYSTEM_HEAP_BYTES = 206,
 | 
			
		||||
    CFG_LOW_MEM_SIMULATION_KB = 207,
 | 
			
		||||
    CFG_BOOTLOADER_BOARD_ID = 208,
 | 
			
		||||
    CFG_UF2_FAMILY = 209,
 | 
			
		||||
    CFG_PINS_PORT_SIZE = 210,
 | 
			
		||||
    CFG_BOOTLOADER_PROTECTION = 211,
 | 
			
		||||
    CFG_POWER_DEEPSLEEP_TIMEOUT = 212,
 | 
			
		||||
    CFG_ANALOG_BUTTON_THRESHOLD = 213,
 | 
			
		||||
    CFG_CPU_MHZ = 214,
 | 
			
		||||
    CFG_CONTROLLER_LIGHT_MAX_BRIGHTNESS = 215,
 | 
			
		||||
    CFG_PIN_B0 = 300,
 | 
			
		||||
    CFG_PIN_B1 = 301,
 | 
			
		||||
    CFG_PIN_B2 = 302,
 | 
			
		||||
    CFG_PIN_B3 = 303,
 | 
			
		||||
    CFG_PIN_B4 = 304,
 | 
			
		||||
    CFG_PIN_B5 = 305,
 | 
			
		||||
    CFG_PIN_B6 = 306,
 | 
			
		||||
    CFG_PIN_B7 = 307,
 | 
			
		||||
    CFG_PIN_B8 = 308,
 | 
			
		||||
    CFG_PIN_B9 = 309,
 | 
			
		||||
    CFG_PIN_B10 = 310,
 | 
			
		||||
    CFG_PIN_B11 = 311,
 | 
			
		||||
    CFG_PIN_B12 = 312,
 | 
			
		||||
    CFG_PIN_B13 = 313,
 | 
			
		||||
    CFG_PIN_B14 = 314,
 | 
			
		||||
    CFG_PIN_B15 = 315,
 | 
			
		||||
    CFG_PIN_B16 = 316,
 | 
			
		||||
    CFG_PIN_B17 = 317,
 | 
			
		||||
    CFG_PIN_B18 = 318,
 | 
			
		||||
    CFG_PIN_B19 = 319,
 | 
			
		||||
    CFG_PIN_B20 = 320,
 | 
			
		||||
    CFG_PIN_B21 = 321,
 | 
			
		||||
    CFG_PIN_B22 = 322,
 | 
			
		||||
    CFG_PIN_B23 = 323,
 | 
			
		||||
    CFG_PIN_B24 = 324,
 | 
			
		||||
    CFG_PIN_B25 = 325,
 | 
			
		||||
    CFG_PIN_B26 = 326,
 | 
			
		||||
    CFG_PIN_B27 = 327,
 | 
			
		||||
    CFG_PIN_B28 = 328,
 | 
			
		||||
    CFG_PIN_B29 = 329,
 | 
			
		||||
    CFG_PIN_B30 = 330,
 | 
			
		||||
    CFG_PIN_B31 = 331,
 | 
			
		||||
    CFG_PIN_C0 = 350,
 | 
			
		||||
    CFG_PIN_C1 = 351,
 | 
			
		||||
    CFG_PIN_C2 = 352,
 | 
			
		||||
    CFG_PIN_C3 = 353,
 | 
			
		||||
    CFG_PIN_C4 = 354,
 | 
			
		||||
    CFG_PIN_C5 = 355,
 | 
			
		||||
    CFG_PIN_C6 = 356,
 | 
			
		||||
    CFG_PIN_C7 = 357,
 | 
			
		||||
    CFG_PIN_C8 = 358,
 | 
			
		||||
    CFG_PIN_C9 = 359,
 | 
			
		||||
    CFG_PIN_C10 = 360,
 | 
			
		||||
    CFG_PIN_C11 = 361,
 | 
			
		||||
    CFG_PIN_C12 = 362,
 | 
			
		||||
    CFG_PIN_C13 = 363,
 | 
			
		||||
    CFG_PIN_C14 = 364,
 | 
			
		||||
    CFG_PIN_C15 = 365,
 | 
			
		||||
    CFG_PIN_C16 = 366,
 | 
			
		||||
    CFG_PIN_C17 = 367,
 | 
			
		||||
    CFG_PIN_C18 = 368,
 | 
			
		||||
    CFG_PIN_C19 = 369,
 | 
			
		||||
    CFG_PIN_C20 = 370,
 | 
			
		||||
    CFG_PIN_C21 = 371,
 | 
			
		||||
    CFG_PIN_C22 = 372,
 | 
			
		||||
    CFG_PIN_C23 = 373,
 | 
			
		||||
    CFG_PIN_C24 = 374,
 | 
			
		||||
    CFG_PIN_C25 = 375,
 | 
			
		||||
    CFG_PIN_C26 = 376,
 | 
			
		||||
    CFG_PIN_C27 = 377,
 | 
			
		||||
    CFG_PIN_C28 = 378,
 | 
			
		||||
    CFG_PIN_C29 = 379,
 | 
			
		||||
    CFG_PIN_C30 = 380,
 | 
			
		||||
    CFG_PIN_C31 = 381,
 | 
			
		||||
    CFG_PIN_P0 = 400,
 | 
			
		||||
    CFG_PIN_P1 = 401,
 | 
			
		||||
    CFG_PIN_P2 = 402,
 | 
			
		||||
    CFG_PIN_P3 = 403,
 | 
			
		||||
    CFG_PIN_P4 = 404,
 | 
			
		||||
    CFG_PIN_P5 = 405,
 | 
			
		||||
    CFG_PIN_P6 = 406,
 | 
			
		||||
    CFG_PIN_P7 = 407,
 | 
			
		||||
    CFG_PIN_P8 = 408,
 | 
			
		||||
    CFG_PIN_P9 = 409,
 | 
			
		||||
    CFG_PIN_P10 = 410,
 | 
			
		||||
    CFG_PIN_P11 = 411,
 | 
			
		||||
    CFG_PIN_P12 = 412,
 | 
			
		||||
    CFG_PIN_P13 = 413,
 | 
			
		||||
    CFG_PIN_P14 = 414,
 | 
			
		||||
    CFG_PIN_P15 = 415,
 | 
			
		||||
    CFG_PIN_P16 = 416,
 | 
			
		||||
    CFG_PIN_P17 = 417,
 | 
			
		||||
    CFG_PIN_P18 = 418,
 | 
			
		||||
    CFG_PIN_P19 = 419,
 | 
			
		||||
    CFG_PIN_P20 = 420,
 | 
			
		||||
    CFG_PIN_P21 = 421,
 | 
			
		||||
    CFG_PIN_P22 = 422,
 | 
			
		||||
    CFG_PIN_P23 = 423,
 | 
			
		||||
    CFG_PIN_P24 = 424,
 | 
			
		||||
    CFG_PIN_P25 = 425,
 | 
			
		||||
    CFG_PIN_P26 = 426,
 | 
			
		||||
    CFG_PIN_P27 = 427,
 | 
			
		||||
    CFG_PIN_P28 = 428,
 | 
			
		||||
    CFG_PIN_P29 = 429,
 | 
			
		||||
    CFG_PIN_P30 = 430,
 | 
			
		||||
    CFG_PIN_P31 = 431,
 | 
			
		||||
    CFG_PIN_LORA_MISO = 1001,
 | 
			
		||||
    CFG_PIN_LORA_MOSI = 1002,
 | 
			
		||||
    CFG_PIN_LORA_SCK = 1003,
 | 
			
		||||
    CFG_PIN_LORA_CS = 1004,
 | 
			
		||||
    CFG_PIN_LORA_BOOT = 1005,
 | 
			
		||||
    CFG_PIN_LORA_RESET = 1006,
 | 
			
		||||
    CFG_PIN_IRRXLED = 1007,
 | 
			
		||||
    CFG_PIN_IRTXLED = 1008,
 | 
			
		||||
    CFG_PIN_LCD_RESET = 1009,
 | 
			
		||||
    CFG_PIN_LCD_ENABLE = 1010,
 | 
			
		||||
    CFG_PIN_LCD_DATALINE4 = 1011,
 | 
			
		||||
    CFG_PIN_LCD_DATALINE5 = 1012,
 | 
			
		||||
    CFG_PIN_LCD_DATALINE6 = 1013,
 | 
			
		||||
    CFG_PIN_LCD_DATALINE7 = 1014,
 | 
			
		||||
    CFG_NUM_LCD_COLUMNS = 1015,
 | 
			
		||||
    CFG_NUM_LCD_ROWS = 1016,
 | 
			
		||||
    // /pxtapp/ev3const.h
 | 
			
		||||
    NUM_INPUTS = 4,
 | 
			
		||||
    NUM_OUTPUTS = 4,
 | 
			
		||||
    LCD_WIDTH = 178,
 | 
			
		||||
@@ -46,44 +345,66 @@ declare const enum DAL {
 | 
			
		||||
    CONN_OUTPUT_TACHO = 125,
 | 
			
		||||
    CONN_NONE = 126,
 | 
			
		||||
    CONN_ERROR = 127,
 | 
			
		||||
    opProgramStart = 0x03,
 | 
			
		||||
    opOutputGetType = 0xA0,
 | 
			
		||||
    opOutputSetType = 0xA1,
 | 
			
		||||
    opOutputReset = 0xA2,
 | 
			
		||||
    opOutputStop = 0xA3,
 | 
			
		||||
    opOutputPower = 0xA4,
 | 
			
		||||
    opOutputSpeed = 0xA5,
 | 
			
		||||
    opOutputStart = 0xA6,
 | 
			
		||||
    opOutputPolarity = 0xA7,
 | 
			
		||||
    opOutputRead = 0xA8,
 | 
			
		||||
    opOutputTest = 0xA9,
 | 
			
		||||
    opOutputReady = 0xAA,
 | 
			
		||||
    opOutputPosition = 0xAB,
 | 
			
		||||
    opOutputStepPower = 0xAC,
 | 
			
		||||
    opOutputTimePower = 0xAD,
 | 
			
		||||
    opOutputStepSpeed = 0xAE,
 | 
			
		||||
    opOutputTimeSpeed = 0xAF,
 | 
			
		||||
    opOutputStepSync = 0xB0,
 | 
			
		||||
    opOutputTimeSync = 0xB1,
 | 
			
		||||
    opOutputClearCount = 0xB2,
 | 
			
		||||
    opOutputGetCount = 0xB3,
 | 
			
		||||
    opOutputProgramStop = 0xB4,
 | 
			
		||||
    BUTTON_ID_UP = 0x01,
 | 
			
		||||
    BUTTON_ID_ENTER = 0x02,
 | 
			
		||||
    BUTTON_ID_DOWN = 0x04,
 | 
			
		||||
    BUTTON_ID_RIGHT = 0x08,
 | 
			
		||||
    BUTTON_ID_LEFT = 0x10,
 | 
			
		||||
    BUTTON_ID_ESCAPE = 0x20,
 | 
			
		||||
    // built/dockermake/pxtapp/pxt.h
 | 
			
		||||
    opProgramStart = 3,
 | 
			
		||||
    opOutputGetType = 160,
 | 
			
		||||
    opOutputSetType = 161,
 | 
			
		||||
    opOutputReset = 162,
 | 
			
		||||
    opOutputStop = 163,
 | 
			
		||||
    opOutputPower = 164,
 | 
			
		||||
    opOutputSpeed = 165,
 | 
			
		||||
    opOutputStart = 166,
 | 
			
		||||
    opOutputPolarity = 167,
 | 
			
		||||
    opOutputRead = 168,
 | 
			
		||||
    opOutputTest = 169,
 | 
			
		||||
    opOutputReady = 170,
 | 
			
		||||
    opOutputPosition = 171,
 | 
			
		||||
    opOutputStepPower = 172,
 | 
			
		||||
    opOutputTimePower = 173,
 | 
			
		||||
    opOutputStepSpeed = 174,
 | 
			
		||||
    opOutputTimeSpeed = 175,
 | 
			
		||||
    opOutputStepSync = 176,
 | 
			
		||||
    opOutputTimeSync = 177,
 | 
			
		||||
    opOutputClearCount = 178,
 | 
			
		||||
    opOutputGetCount = 179,
 | 
			
		||||
    opOutputProgramStop = 180,
 | 
			
		||||
    BUTTON_ID_UP = 1,
 | 
			
		||||
    BUTTON_ID_ENTER = 2,
 | 
			
		||||
    BUTTON_ID_DOWN = 4,
 | 
			
		||||
    BUTTON_ID_RIGHT = 8,
 | 
			
		||||
    BUTTON_ID_LEFT = 16,
 | 
			
		||||
    BUTTON_ID_ESCAPE = 32,
 | 
			
		||||
    // /pxtapp/platform.h
 | 
			
		||||
    PXT_GC_THREAD_LIST = 1,
 | 
			
		||||
    // /pxtapp/pxt.h
 | 
			
		||||
    DEVICE_EVT_ANY = 0,
 | 
			
		||||
    DEVICE_ID_NOTIFY = 10000,
 | 
			
		||||
    DEVICE_ID_NOTIFY_ONE = 10001,
 | 
			
		||||
    // built/dockermake/pxtapp/pxtbase.h
 | 
			
		||||
    PXT_REF_TAG_STRING = 1,
 | 
			
		||||
    PXT_REF_TAG_BUFFER = 2,
 | 
			
		||||
    PXT_REF_TAG_IMAGE = 3,
 | 
			
		||||
    PXT_REF_TAG_NUMBER = 32,
 | 
			
		||||
    PXT_REF_TAG_ACTION = 33,
 | 
			
		||||
    IMAGE_BITS = 1,
 | 
			
		||||
    // /pxtapp/pxtbase.h
 | 
			
		||||
    PXT32 = 1,
 | 
			
		||||
    PXT64 = 1,
 | 
			
		||||
    PXT_VTABLE_SHIFT = 2,
 | 
			
		||||
    PXT_REFCNT_FLASH = 65534,
 | 
			
		||||
    VTABLE_MAGIC = 249,
 | 
			
		||||
    Undefined = 0,
 | 
			
		||||
    Boolean = 1,
 | 
			
		||||
    Number = 2,
 | 
			
		||||
    String = 3,
 | 
			
		||||
    Object = 4,
 | 
			
		||||
    Function = 5,
 | 
			
		||||
    BoxedString = 1,
 | 
			
		||||
    BoxedNumber = 2,
 | 
			
		||||
    BoxedBuffer = 3,
 | 
			
		||||
    RefAction = 4,
 | 
			
		||||
    RefImage = 5,
 | 
			
		||||
    RefCollection = 6,
 | 
			
		||||
    RefRefLocal = 7,
 | 
			
		||||
    RefMap = 8,
 | 
			
		||||
    RefMImage = 9,
 | 
			
		||||
    MMap = 10,
 | 
			
		||||
    User0 = 16,
 | 
			
		||||
    PXT_IOS_HEAP_ALLOC_BITS = 20,
 | 
			
		||||
    IMAGE_HEADER_MAGIC = 135,
 | 
			
		||||
    Int8LE = 1,
 | 
			
		||||
    UInt8LE = 2,
 | 
			
		||||
    Int16LE = 3,
 | 
			
		||||
@@ -100,12 +421,10 @@ declare const enum DAL {
 | 
			
		||||
    Float64LE = 14,
 | 
			
		||||
    Float32BE = 15,
 | 
			
		||||
    Float64BE = 16,
 | 
			
		||||
    Undefined = 0,
 | 
			
		||||
    Boolean = 1,
 | 
			
		||||
    Number = 2,
 | 
			
		||||
    String = 3,
 | 
			
		||||
    Object = 4,
 | 
			
		||||
    Function = 5,
 | 
			
		||||
    // built/dockermake/pxtapp/pxtconfig.h
 | 
			
		||||
    // built/dockermake/pxtapp/pxtcore.h
 | 
			
		||||
    NUM_TRY_FRAME_REGS = 3,
 | 
			
		||||
    GC = 0,
 | 
			
		||||
    // /pxtapp/pxtconfig.h
 | 
			
		||||
    PXT_GC = 1,
 | 
			
		||||
    // /pxtapp/pxtcore.h
 | 
			
		||||
    PXT_HARD_FLOAT = 1,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,589 +0,0 @@
 | 
			
		||||
#include "pxt.h"
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <sys/time.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <cstdarg>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <dirent.h>
 | 
			
		||||
#include <signal.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#include "ev3const.h"
 | 
			
		||||
 | 
			
		||||
#define THREAD_DBG(...)
 | 
			
		||||
 | 
			
		||||
#define MALLOC_LIMIT (8 * 1024 * 1024)
 | 
			
		||||
#define MALLOC_CHECK_PERIOD (1024 * 1024)
 | 
			
		||||
 | 
			
		||||
void *xmalloc(size_t sz) {
 | 
			
		||||
    static size_t allocBytes = 0;
 | 
			
		||||
    allocBytes += sz;
 | 
			
		||||
    if (allocBytes >= MALLOC_CHECK_PERIOD) {
 | 
			
		||||
        allocBytes = 0;
 | 
			
		||||
        auto info = mallinfo();
 | 
			
		||||
        DMESG("malloc used: %d kb", info.uordblks / 1024);
 | 
			
		||||
        if (info.uordblks > MALLOC_LIMIT) {
 | 
			
		||||
            target_panic(904);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    auto r = malloc(sz);
 | 
			
		||||
    if (r == NULL)
 | 
			
		||||
        target_panic(905); // shouldn't happen
 | 
			
		||||
    return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *operator new(size_t size) {
 | 
			
		||||
    return xmalloc(size);
 | 
			
		||||
}
 | 
			
		||||
void *operator new[](size_t size) {
 | 
			
		||||
    return xmalloc(size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete(void *p) {
 | 
			
		||||
    free(p);
 | 
			
		||||
}
 | 
			
		||||
void operator delete[](void *p) {
 | 
			
		||||
    free(p);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace pxt {
 | 
			
		||||
 | 
			
		||||
static int startTime;
 | 
			
		||||
static pthread_mutex_t execMutex;
 | 
			
		||||
static pthread_mutex_t eventMutex;
 | 
			
		||||
static pthread_cond_t newEventBroadcast;
 | 
			
		||||
 | 
			
		||||
struct Thread {
 | 
			
		||||
    struct Thread *next;
 | 
			
		||||
    Action act;
 | 
			
		||||
    TValue arg0;
 | 
			
		||||
    pthread_t pid;
 | 
			
		||||
    pthread_cond_t waitCond;
 | 
			
		||||
    int waitSource;
 | 
			
		||||
    int waitValue;
 | 
			
		||||
    TValue data0;
 | 
			
		||||
    TValue data1;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct Thread *allThreads;
 | 
			
		||||
static struct Event *eventHead, *eventTail;
 | 
			
		||||
static int usbFD;
 | 
			
		||||
static int dmesgPtr;
 | 
			
		||||
static int dmesgSerialPtr;
 | 
			
		||||
static char dmesgBuf[4096];
 | 
			
		||||
 | 
			
		||||
struct Event {
 | 
			
		||||
    struct Event *next;
 | 
			
		||||
    int source;
 | 
			
		||||
    int value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Event lastEvent;
 | 
			
		||||
 | 
			
		||||
Event *mkEvent(int source, int value) {
 | 
			
		||||
    auto res = new Event();
 | 
			
		||||
    memset(res, 0, sizeof(Event));
 | 
			
		||||
    res->source = source;
 | 
			
		||||
    res->value = value;
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define USB_MAGIC 0x3d3f
 | 
			
		||||
#define USB_SERIAL 1
 | 
			
		||||
#define USB_RESTART 2
 | 
			
		||||
#define USB_DMESG 3
 | 
			
		||||
 | 
			
		||||
struct UsbPacket {
 | 
			
		||||
    uint16_t size;
 | 
			
		||||
    uint16_t msgcount;
 | 
			
		||||
    uint16_t magic;
 | 
			
		||||
    uint16_t code;
 | 
			
		||||
    char buf[1024 - 8];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void *usbThread(void *) {
 | 
			
		||||
    UsbPacket pkt;
 | 
			
		||||
    UsbPacket resp;
 | 
			
		||||
    while (true) {
 | 
			
		||||
        int len = read(usbFD, &pkt, sizeof(pkt));
 | 
			
		||||
        if (len <= 4) {
 | 
			
		||||
            sleep_core_us(20000);
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        resp.msgcount = pkt.msgcount;
 | 
			
		||||
        if (pkt.magic == USB_MAGIC) {
 | 
			
		||||
            if (pkt.code == USB_RESTART) {
 | 
			
		||||
                target_reset();
 | 
			
		||||
            } else if (pkt.code == USB_DMESG) {
 | 
			
		||||
                dumpDmesg();
 | 
			
		||||
            }
 | 
			
		||||
            /*
 | 
			
		||||
            resp.magic = pkt.magic;
 | 
			
		||||
            resp.code = pkt.code;
 | 
			
		||||
            resp.size = 8;
 | 
			
		||||
            write(usbFD, &resp, sizeof(resp));
 | 
			
		||||
            */
 | 
			
		||||
        } else {
 | 
			
		||||
            resp.magic = 0xffff;
 | 
			
		||||
            resp.size = 4;
 | 
			
		||||
            write(usbFD, &resp, sizeof(resp));
 | 
			
		||||
        }
 | 
			
		||||
        sleep_core_us(1000);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void startUsb() {
 | 
			
		||||
    usbFD = open("/dev/lms_usbdev", O_RDWR, 0666);
 | 
			
		||||
    pthread_t pid;
 | 
			
		||||
    pthread_create(&pid, NULL, usbThread, NULL);
 | 
			
		||||
    pthread_detach(pid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *exitThread(void *) {
 | 
			
		||||
    int fd = open("/dev/lms_ui", O_RDWR, 0666);
 | 
			
		||||
    if (fd < 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
    uint8_t *data =
 | 
			
		||||
        (uint8_t *)mmap(NULL, NUM_BUTTONS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
			
		||||
    if (data == MAP_FAILED) {
 | 
			
		||||
        close(fd);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    for (;;) {
 | 
			
		||||
        if (data[5])
 | 
			
		||||
            target_reset();
 | 
			
		||||
        sleep_core_us(50000);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void startExitThread() {
 | 
			
		||||
    pthread_t pid;
 | 
			
		||||
    pthread_create(&pid, NULL, exitThread, NULL);
 | 
			
		||||
    pthread_detach(pid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sendUsb(uint16_t code, const char *data, int len) {
 | 
			
		||||
    while (len > 0) {
 | 
			
		||||
        int sz = len;
 | 
			
		||||
        if (sz > 1000)
 | 
			
		||||
            sz = 1000;
 | 
			
		||||
        UsbPacket pkt = {(uint16_t)(6 + sz), 0, USB_MAGIC, code, {}};
 | 
			
		||||
        memcpy(pkt.buf, data, sz);
 | 
			
		||||
        write(usbFD, &pkt, sizeof(pkt));
 | 
			
		||||
        len -= sz;
 | 
			
		||||
        data += sz;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sendSerial(const char *data, int len) {
 | 
			
		||||
    sendUsb(USB_SERIAL, data, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
volatile bool paniced;
 | 
			
		||||
extern "C" void drawPanic(int code);
 | 
			
		||||
 | 
			
		||||
extern "C" void target_panic(int error_code) {
 | 
			
		||||
    char buf[50];
 | 
			
		||||
    paniced = true;
 | 
			
		||||
    pthread_mutex_trylock(&execMutex);
 | 
			
		||||
 | 
			
		||||
    snprintf(buf, sizeof(buf), "\nPANIC %d\n", error_code);
 | 
			
		||||
 | 
			
		||||
    drawPanic(error_code);
 | 
			
		||||
    DMESG("PANIC %d", error_code);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < 10; ++i) {
 | 
			
		||||
        sendSerial(buf, strlen(buf));
 | 
			
		||||
        sleep_core_us(500 * 1000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    target_reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void startUser() {
 | 
			
		||||
    pthread_mutex_lock(&execMutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void stopUser() {
 | 
			
		||||
    pthread_mutex_unlock(&execMutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sleep_core_us(uint64_t us) {
 | 
			
		||||
    struct timespec ts;
 | 
			
		||||
    ts.tv_sec = us / 1000000;
 | 
			
		||||
    ts.tv_nsec = (us % 1000000) * 1000;
 | 
			
		||||
    while (nanosleep(&ts, &ts))
 | 
			
		||||
        ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sleep_ms(uint32_t ms) {
 | 
			
		||||
    stopUser();
 | 
			
		||||
    sleep_core_us(ms * 1000);
 | 
			
		||||
    startUser();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sleep_us(uint64_t us) {
 | 
			
		||||
    if (us > 50000) {
 | 
			
		||||
        sleep_ms(us / 1000);
 | 
			
		||||
    }
 | 
			
		||||
    sleep_core_us(us);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t currTime() {
 | 
			
		||||
    struct timeval tv;
 | 
			
		||||
    gettimeofday(&tv, NULL);
 | 
			
		||||
    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int current_time_ms() {
 | 
			
		||||
    return currTime() - startTime;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void disposeThread(Thread *t) {
 | 
			
		||||
    if (allThreads == t) {
 | 
			
		||||
        allThreads = t->next;
 | 
			
		||||
    } else {
 | 
			
		||||
        for (auto tt = allThreads; tt; tt = tt->next) {
 | 
			
		||||
            if (tt->next == t) {
 | 
			
		||||
                tt->next = t->next;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    decr(t->act);
 | 
			
		||||
    decr(t->arg0);
 | 
			
		||||
    decr(t->data0);
 | 
			
		||||
    decr(t->data1);
 | 
			
		||||
    pthread_cond_destroy(&t->waitCond);
 | 
			
		||||
    delete t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void runAct(Thread *thr) {
 | 
			
		||||
    startUser();
 | 
			
		||||
    pxt::runAction1(thr->act, thr->arg0);
 | 
			
		||||
    stopUser();
 | 
			
		||||
    disposeThread(thr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void mainThread(Thread *) {}
 | 
			
		||||
 | 
			
		||||
void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TValue d0 = 0,
 | 
			
		||||
                 TValue d1 = 0) {
 | 
			
		||||
    if (runner == NULL)
 | 
			
		||||
        runner = runAct;
 | 
			
		||||
    auto thr = new Thread();
 | 
			
		||||
    memset(thr, 0, sizeof(Thread));
 | 
			
		||||
    thr->next = allThreads;
 | 
			
		||||
    allThreads = thr;
 | 
			
		||||
    thr->act = incr(a);
 | 
			
		||||
    thr->arg0 = incr(arg);
 | 
			
		||||
    thr->data0 = incr(d0);
 | 
			
		||||
    thr->data1 = incr(d1);
 | 
			
		||||
    pthread_cond_init(&thr->waitCond, NULL);
 | 
			
		||||
    if (runner == mainThread) {
 | 
			
		||||
        thr->pid = pthread_self();
 | 
			
		||||
    } else {
 | 
			
		||||
        pthread_create(&thr->pid, NULL, (void *(*)(void *))runner, thr);
 | 
			
		||||
        THREAD_DBG("setup thread: %p (pid %p)", thr, thr->pid);
 | 
			
		||||
        pthread_detach(thr->pid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void releaseFiber() {
 | 
			
		||||
    stopUser();
 | 
			
		||||
    pthread_exit(NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void runInParallel(Action a) {
 | 
			
		||||
    setupThread(a);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void runFor(Thread *t) {
 | 
			
		||||
    startUser();
 | 
			
		||||
    while (true) {
 | 
			
		||||
        pxt::runAction0(t->act);
 | 
			
		||||
        sleep_ms(20);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void runForever(Action a) {
 | 
			
		||||
    setupThread(a, 0, runFor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void waitForEvent(int source, int value) {
 | 
			
		||||
    THREAD_DBG("waitForEv: %d %d", source, value);
 | 
			
		||||
    auto self = pthread_self();
 | 
			
		||||
    for (auto t = allThreads; t; t = t->next) {
 | 
			
		||||
        THREAD_DBG("t: %p", t);
 | 
			
		||||
        if (t->pid == self) {
 | 
			
		||||
            pthread_mutex_lock(&eventMutex);
 | 
			
		||||
            t->waitSource = source;
 | 
			
		||||
            t->waitValue = value;
 | 
			
		||||
            stopUser();
 | 
			
		||||
            // spourious wake ups may occur they say
 | 
			
		||||
            while (t->waitSource) {
 | 
			
		||||
                pthread_cond_wait(&t->waitCond, &eventMutex);
 | 
			
		||||
            }
 | 
			
		||||
            pthread_mutex_unlock(&eventMutex);
 | 
			
		||||
            startUser();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    DMESG("current thread not registered!");
 | 
			
		||||
    target_panic(901);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void dispatchEvent(Event &e) {
 | 
			
		||||
    lastEvent = e;
 | 
			
		||||
 | 
			
		||||
    auto curr = findBinding(e.source, e.value);
 | 
			
		||||
    if (curr)
 | 
			
		||||
        setupThread(curr->action, fromInt(e.value));
 | 
			
		||||
 | 
			
		||||
    curr = findBinding(e.source, DEVICE_EVT_ANY);
 | 
			
		||||
    if (curr)
 | 
			
		||||
        setupThread(curr->action, fromInt(e.value));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *evtDispatcher(void *dummy) {
 | 
			
		||||
    pthread_mutex_lock(&eventMutex);
 | 
			
		||||
    while (true) {
 | 
			
		||||
        pthread_cond_wait(&newEventBroadcast, &eventMutex);
 | 
			
		||||
        while (eventHead != NULL) {
 | 
			
		||||
            if (paniced)
 | 
			
		||||
                return 0;
 | 
			
		||||
            Event *ev = eventHead;
 | 
			
		||||
            eventHead = ev->next;
 | 
			
		||||
            if (eventHead == NULL)
 | 
			
		||||
                eventTail = NULL;
 | 
			
		||||
 | 
			
		||||
            for (auto thr = allThreads; thr; thr = thr->next) {
 | 
			
		||||
                if (paniced)
 | 
			
		||||
                    return 0;
 | 
			
		||||
                if (thr->waitSource == 0)
 | 
			
		||||
                    continue;
 | 
			
		||||
                if (thr->waitValue != ev->value && thr->waitValue != DEVICE_EVT_ANY)
 | 
			
		||||
                    continue;
 | 
			
		||||
                if (thr->waitSource == ev->source) {
 | 
			
		||||
                    thr->waitSource = 0; // once!
 | 
			
		||||
                    pthread_cond_broadcast(&thr->waitCond);
 | 
			
		||||
                } else if (thr->waitSource == DEVICE_ID_NOTIFY &&
 | 
			
		||||
                           ev->source == DEVICE_ID_NOTIFY_ONE) {
 | 
			
		||||
                    thr->waitSource = 0; // once!
 | 
			
		||||
                    pthread_cond_broadcast(&thr->waitCond);
 | 
			
		||||
                    break; // do not wake up any other threads
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            dispatchEvent(*ev);
 | 
			
		||||
            delete ev;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int allocateNotifyEvent() {
 | 
			
		||||
    static volatile int notifyId;
 | 
			
		||||
    pthread_mutex_lock(&eventMutex);
 | 
			
		||||
    int res = ++notifyId;
 | 
			
		||||
    pthread_mutex_unlock(&eventMutex);
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void raiseEvent(int id, int event) {
 | 
			
		||||
    auto e = mkEvent(id, event);
 | 
			
		||||
    pthread_mutex_lock(&eventMutex);
 | 
			
		||||
    if (eventTail == NULL) {
 | 
			
		||||
        if (eventHead != NULL)
 | 
			
		||||
            target_panic(902);
 | 
			
		||||
        eventHead = eventTail = e;
 | 
			
		||||
    } else {
 | 
			
		||||
        eventTail->next = e;
 | 
			
		||||
        eventTail = e;
 | 
			
		||||
    }
 | 
			
		||||
    pthread_cond_broadcast(&newEventBroadcast);
 | 
			
		||||
    pthread_mutex_unlock(&eventMutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void registerWithDal(int id, int event, Action a, int flags) {
 | 
			
		||||
    // TODO support flags
 | 
			
		||||
    setBinding(id, event, a);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void runPoller(Thread *thr) {
 | 
			
		||||
    Action query = thr->data0;
 | 
			
		||||
    auto us = (uint64_t)toInt(thr->data1) * 1000;
 | 
			
		||||
 | 
			
		||||
    // note that this is run without the user mutex held - it should not modify any state!
 | 
			
		||||
    TValue prev = pxt::runAction0(query);
 | 
			
		||||
 | 
			
		||||
    startUser();
 | 
			
		||||
    pxt::runAction2(thr->act, prev, prev);
 | 
			
		||||
    stopUser();
 | 
			
		||||
 | 
			
		||||
    while (true) {
 | 
			
		||||
        sleep_core_us(us);
 | 
			
		||||
        if (paniced)
 | 
			
		||||
            break;
 | 
			
		||||
        TValue curr = pxt::runAction0(query);
 | 
			
		||||
        if (curr != prev) {
 | 
			
		||||
            startUser();
 | 
			
		||||
            pxt::runAction2(thr->act, prev, curr);
 | 
			
		||||
            stopUser();
 | 
			
		||||
            if (paniced)
 | 
			
		||||
                break;
 | 
			
		||||
            decr(prev);
 | 
			
		||||
            prev = curr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    //    disposeThread(thr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t afterProgramPage() {
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
void dumpDmesg() {
 | 
			
		||||
    auto len = dmesgPtr - dmesgSerialPtr;
 | 
			
		||||
    if (len == 0)
 | 
			
		||||
        return;
 | 
			
		||||
    sendSerial(dmesgBuf + dmesgSerialPtr, len);
 | 
			
		||||
    dmesgSerialPtr = dmesgPtr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int lmsPid;
 | 
			
		||||
void stopLMS() {
 | 
			
		||||
    struct dirent *ent;
 | 
			
		||||
    DIR *dir;
 | 
			
		||||
 | 
			
		||||
    dir = opendir("/proc");
 | 
			
		||||
    if (dir == NULL)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    while ((ent = readdir(dir)) != NULL) {
 | 
			
		||||
        int pid = atoi(ent->d_name);
 | 
			
		||||
        if (!pid)
 | 
			
		||||
            continue;
 | 
			
		||||
        char namebuf[100];
 | 
			
		||||
        snprintf(namebuf, 1000, "/proc/%d/cmdline", pid);
 | 
			
		||||
        FILE *f = fopen(namebuf, "r");
 | 
			
		||||
        if (f) {
 | 
			
		||||
            fread(namebuf, 1, 99, f);
 | 
			
		||||
            if (strcmp(namebuf, "./lms2012") == 0) {
 | 
			
		||||
                lmsPid = pid;
 | 
			
		||||
            }
 | 
			
		||||
            fclose(f);
 | 
			
		||||
            if (lmsPid)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    closedir(dir);
 | 
			
		||||
 | 
			
		||||
    lmsPid = 0; // disable SIGSTOP for now - rethink if problems with I2C (runs on a thread)
 | 
			
		||||
 | 
			
		||||
    if (lmsPid) {
 | 
			
		||||
        DMESG("SIGSTOP to lmsPID=%d", lmsPid);
 | 
			
		||||
        if (kill(lmsPid, SIGSTOP))
 | 
			
		||||
            DMESG("SIGSTOP failed");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void runLMS() {
 | 
			
		||||
    DMESG("re-starting LMS2012");
 | 
			
		||||
    kill(lmsPid, SIGCONT);
 | 
			
		||||
    sleep_core_us(200000);
 | 
			
		||||
    exit(0);
 | 
			
		||||
    /*
 | 
			
		||||
    chdir("/home/root/lms2012/sys");
 | 
			
		||||
    for (int fd = 3; fd < 9999; ++fd)
 | 
			
		||||
        close(fd);
 | 
			
		||||
    execl("lms2012", "./lms2012");
 | 
			
		||||
    exit(100); // should not be reached
 | 
			
		||||
    */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void stopMotors() {
 | 
			
		||||
    uint8_t cmd[3] = {opOutputStop, 0x0F, 0};
 | 
			
		||||
    int fd = open("/dev/lms_pwm", O_RDWR);
 | 
			
		||||
    write(fd, cmd, 3);
 | 
			
		||||
    close(fd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void stopProgram() {
 | 
			
		||||
    uint8_t cmd[1] = {opOutputProgramStop};
 | 
			
		||||
    int fd = open("/dev/lms_pwm", O_RDWR);
 | 
			
		||||
    write(fd, cmd, 1);
 | 
			
		||||
    close(fd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void target_reset() {
 | 
			
		||||
    pthread_mutex_trylock(&execMutex);
 | 
			
		||||
    stopMotors();
 | 
			
		||||
    stopProgram();
 | 
			
		||||
    if (lmsPid)
 | 
			
		||||
        runLMS();
 | 
			
		||||
    else
 | 
			
		||||
        exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void screen_init();
 | 
			
		||||
void initRuntime() {
 | 
			
		||||
    // daemon(1, 1);
 | 
			
		||||
    startTime = currTime();
 | 
			
		||||
    DMESG("runtime starting...");
 | 
			
		||||
    stopLMS();
 | 
			
		||||
    startUsb();
 | 
			
		||||
    startExitThread();
 | 
			
		||||
    pthread_t disp;
 | 
			
		||||
    pthread_create(&disp, NULL, evtDispatcher, NULL);
 | 
			
		||||
    pthread_detach(disp);
 | 
			
		||||
    setupThread(0, 0, mainThread);
 | 
			
		||||
    target_init();
 | 
			
		||||
    screen_init();
 | 
			
		||||
    startUser();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static FILE *dmesgFile;
 | 
			
		||||
 | 
			
		||||
void dmesgRaw(const char *buf, uint32_t len) {
 | 
			
		||||
    if (!dmesgFile) {
 | 
			
		||||
        dmesgFile = fopen("/tmp/dmesg.txt", "w");
 | 
			
		||||
        if (!dmesgFile)
 | 
			
		||||
            dmesgFile = stderr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (len > sizeof(dmesgBuf) / 2)
 | 
			
		||||
        return;
 | 
			
		||||
    if (dmesgPtr + len > sizeof(dmesgBuf)) {
 | 
			
		||||
        dmesgPtr = 0;
 | 
			
		||||
        dmesgSerialPtr = 0;
 | 
			
		||||
    }
 | 
			
		||||
    memcpy(dmesgBuf + dmesgPtr, buf, len);
 | 
			
		||||
    dmesgPtr += len;
 | 
			
		||||
    fwrite(buf, 1, len, dmesgFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dmesg(const char *format, ...) {
 | 
			
		||||
    char buf[500];
 | 
			
		||||
 | 
			
		||||
    snprintf(buf, sizeof(buf), "[%8d] ", current_time_ms());
 | 
			
		||||
    dmesgRaw(buf, strlen(buf));
 | 
			
		||||
 | 
			
		||||
    va_list arg;
 | 
			
		||||
    va_start(arg, format);
 | 
			
		||||
    vsnprintf(buf, sizeof(buf), format, arg);
 | 
			
		||||
    va_end(arg);
 | 
			
		||||
    dmesgRaw(buf, strlen(buf));
 | 
			
		||||
    dmesgRaw("\n", 1);
 | 
			
		||||
 | 
			
		||||
    fflush(dmesgFile);
 | 
			
		||||
    fdatasync(fileno(dmesgFile));
 | 
			
		||||
}
 | 
			
		||||
} // namespace pxt
 | 
			
		||||
@@ -25,13 +25,20 @@ PXT_VTABLE_CTOR(MMap) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MMap::print() {
 | 
			
		||||
    DMESG("MMap %p r=%d len=%d fd=%d data=%p", this, refcnt, length, fd, data);
 | 
			
		||||
    DMESG("MMap %p len=%d fd=%d data=%p", this, length, fd, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MMap::destroy() {
 | 
			
		||||
    munmap(data, length);
 | 
			
		||||
    close(fd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MMap::scan(MMap *) {}
 | 
			
		||||
 | 
			
		||||
unsigned MMap::gcsize(MMap *) {
 | 
			
		||||
    return TOWORDS(sizeof(MMap));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace control {
 | 
			
		||||
@@ -39,8 +46,8 @@ namespace control {
 | 
			
		||||
/** Create new file mapping in memory */
 | 
			
		||||
//%
 | 
			
		||||
MMap *mmap(String filename, int size, int offset) {
 | 
			
		||||
    DMESG("mmap %s len=%d off=%d", filename->data, size, offset);
 | 
			
		||||
    int fd = open(filename->data, O_RDWR, 0);
 | 
			
		||||
    DMESG("mmap %s len=%d off=%d", filename->getUTF8Data(), size, offset);
 | 
			
		||||
    int fd = open(filename->getUTF8Data(), O_RDWR, 0);
 | 
			
		||||
    if (fd < 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -918,9 +918,3 @@ namespace motors {
 | 
			
		||||
        writePWM(b)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
interface Buffer {
 | 
			
		||||
    [index: number]: number;
 | 
			
		||||
    // rest defined in buffer.cpp
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										199
									
								
								libs/core/platform.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										199
									
								
								libs/core/platform.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,199 @@
 | 
			
		||||
#include "pxt.h"
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <signal.h>
 | 
			
		||||
#include <dirent.h>
 | 
			
		||||
#include "ev3const.h"
 | 
			
		||||
 | 
			
		||||
namespace pxt {
 | 
			
		||||
 | 
			
		||||
    static int usbFD;
 | 
			
		||||
 | 
			
		||||
#define USB_MAGIC 0x3d3f
 | 
			
		||||
#define USB_SERIAL 1
 | 
			
		||||
#define USB_RESTART 2
 | 
			
		||||
#define USB_DMESG 3
 | 
			
		||||
 | 
			
		||||
struct UsbPacket {
 | 
			
		||||
    uint16_t size;
 | 
			
		||||
    uint16_t msgcount;
 | 
			
		||||
    uint16_t magic;
 | 
			
		||||
    uint16_t code;
 | 
			
		||||
    char buf[1024 - 8];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void *usbThread(void *) {
 | 
			
		||||
    UsbPacket pkt;
 | 
			
		||||
    UsbPacket resp;
 | 
			
		||||
    while (true) {
 | 
			
		||||
        int len = read(usbFD, &pkt, sizeof(pkt));
 | 
			
		||||
        if (len <= 4) {
 | 
			
		||||
            sleep_core_us(20000);
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        resp.msgcount = pkt.msgcount;
 | 
			
		||||
        if (pkt.magic == USB_MAGIC) {
 | 
			
		||||
            if (pkt.code == USB_RESTART) {
 | 
			
		||||
                target_reset();
 | 
			
		||||
            } else if (pkt.code == USB_DMESG) {
 | 
			
		||||
                dumpDmesg();
 | 
			
		||||
            }
 | 
			
		||||
            /*
 | 
			
		||||
            resp.magic = pkt.magic;
 | 
			
		||||
            resp.code = pkt.code;
 | 
			
		||||
            resp.size = 8;
 | 
			
		||||
            write(usbFD, &resp, sizeof(resp));
 | 
			
		||||
            */
 | 
			
		||||
        } else {
 | 
			
		||||
            resp.magic = 0xffff;
 | 
			
		||||
            resp.size = 4;
 | 
			
		||||
            write(usbFD, &resp, sizeof(resp));
 | 
			
		||||
        }
 | 
			
		||||
        sleep_core_us(1000);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void startUsb() {
 | 
			
		||||
    usbFD = open("/dev/lms_usbdev", O_RDWR, 0666);
 | 
			
		||||
    pthread_t pid;
 | 
			
		||||
    pthread_create(&pid, NULL, usbThread, NULL);
 | 
			
		||||
    pthread_detach(pid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *exitThread(void *) {
 | 
			
		||||
    int fd = open("/dev/lms_ui", O_RDWR, 0666);
 | 
			
		||||
    if (fd < 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
    uint8_t *data =
 | 
			
		||||
        (uint8_t *)mmap(NULL, NUM_BUTTONS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
			
		||||
    if (data == MAP_FAILED) {
 | 
			
		||||
        close(fd);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    for (;;) {
 | 
			
		||||
        if (data[5])
 | 
			
		||||
            target_reset();
 | 
			
		||||
        sleep_core_us(50000);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void startExitThread() {
 | 
			
		||||
    pthread_t pid;
 | 
			
		||||
    pthread_create(&pid, NULL, exitThread, NULL);
 | 
			
		||||
    pthread_detach(pid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sendUsb(uint16_t code, const char *data, int len) {
 | 
			
		||||
    while (len > 0) {
 | 
			
		||||
        int sz = len;
 | 
			
		||||
        if (sz > 1000)
 | 
			
		||||
            sz = 1000;
 | 
			
		||||
        UsbPacket pkt = {(uint16_t)(6 + sz), 0, USB_MAGIC, code, {}};
 | 
			
		||||
        memcpy(pkt.buf, data, sz);
 | 
			
		||||
        write(usbFD, &pkt, sizeof(pkt));
 | 
			
		||||
        len -= sz;
 | 
			
		||||
        data += sz;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sendSerial(const char *data, int len) {
 | 
			
		||||
    sendUsb(USB_SERIAL, data, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int lmsPid;
 | 
			
		||||
void stopLMS() {
 | 
			
		||||
    struct dirent *ent;
 | 
			
		||||
    DIR *dir;
 | 
			
		||||
 | 
			
		||||
    dir = opendir("/proc");
 | 
			
		||||
    if (dir == NULL)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    while ((ent = readdir(dir)) != NULL) {
 | 
			
		||||
        int pid = atoi(ent->d_name);
 | 
			
		||||
        if (!pid)
 | 
			
		||||
            continue;
 | 
			
		||||
        char namebuf[100];
 | 
			
		||||
        snprintf(namebuf, 1000, "/proc/%d/cmdline", pid);
 | 
			
		||||
        FILE *f = fopen(namebuf, "r");
 | 
			
		||||
        if (f) {
 | 
			
		||||
            fread(namebuf, 1, 99, f);
 | 
			
		||||
            if (strcmp(namebuf, "./lms2012") == 0) {
 | 
			
		||||
                lmsPid = pid;
 | 
			
		||||
            }
 | 
			
		||||
            fclose(f);
 | 
			
		||||
            if (lmsPid)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    closedir(dir);
 | 
			
		||||
 | 
			
		||||
    lmsPid = 0; // disable SIGSTOP for now - rethink if problems with I2C (runs on a thread)
 | 
			
		||||
 | 
			
		||||
    if (lmsPid) {
 | 
			
		||||
        DMESG("SIGSTOP to lmsPID=%d", lmsPid);
 | 
			
		||||
        if (kill(lmsPid, SIGSTOP))
 | 
			
		||||
            DMESG("SIGSTOP failed");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void runLMS() {
 | 
			
		||||
    DMESG("re-starting LMS2012");
 | 
			
		||||
    kill(lmsPid, SIGCONT);
 | 
			
		||||
    sleep_core_us(200000);
 | 
			
		||||
    exit(0);
 | 
			
		||||
    /*
 | 
			
		||||
    chdir("/home/root/lms2012/sys");
 | 
			
		||||
    for (int fd = 3; fd < 9999; ++fd)
 | 
			
		||||
        close(fd);
 | 
			
		||||
    execl("lms2012", "./lms2012");
 | 
			
		||||
    exit(100); // should not be reached
 | 
			
		||||
    */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void stopMotors() {
 | 
			
		||||
    uint8_t cmd[3] = {opOutputStop, 0x0F, 0};
 | 
			
		||||
    int fd = open("/dev/lms_pwm", O_RDWR);
 | 
			
		||||
    write(fd, cmd, 3);
 | 
			
		||||
    close(fd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void stopProgram() {
 | 
			
		||||
    uint8_t cmd[1] = {opOutputProgramStop};
 | 
			
		||||
    int fd = open("/dev/lms_pwm", O_RDWR);
 | 
			
		||||
    write(fd, cmd, 1);
 | 
			
		||||
    close(fd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" void target_reset() {
 | 
			
		||||
    tryLockUser();
 | 
			
		||||
    stopMotors();
 | 
			
		||||
    stopProgram();
 | 
			
		||||
    if (lmsPid)
 | 
			
		||||
        runLMS();
 | 
			
		||||
    else
 | 
			
		||||
        exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void target_exit() {
 | 
			
		||||
    target_reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void target_startup() {
 | 
			
		||||
    stopLMS();
 | 
			
		||||
    startUsb();
 | 
			
		||||
    startExitThread();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void initKeys() {}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1 +1,3 @@
 | 
			
		||||
// leave empty
 | 
			
		||||
#define PXT_GC_THREAD_LIST 1
 | 
			
		||||
 | 
			
		||||
#define PXT_IN_ISR() false
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ int allocateNotifyEvent();
 | 
			
		||||
void sleep_core_us(uint64_t us);
 | 
			
		||||
void startUser();
 | 
			
		||||
void stopUser();
 | 
			
		||||
int tryLockUser();
 | 
			
		||||
 | 
			
		||||
class Button;
 | 
			
		||||
typedef Button *Button_;
 | 
			
		||||
@@ -27,9 +28,13 @@ class MMap : public RefObject {
 | 
			
		||||
    MMap();
 | 
			
		||||
    void destroy();
 | 
			
		||||
    void print();
 | 
			
		||||
 | 
			
		||||
    static void scan(MMap *);
 | 
			
		||||
    static unsigned gcsize(MMap *);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern volatile bool paniced;
 | 
			
		||||
void target_exit();
 | 
			
		||||
 | 
			
		||||
// Buffer, Sound, and Image share representation.
 | 
			
		||||
typedef Buffer Sound;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,11 +26,19 @@
 | 
			
		||||
        "icons.jres",
 | 
			
		||||
        "ns.ts",
 | 
			
		||||
        "platform.h",
 | 
			
		||||
        "platform.cpp",
 | 
			
		||||
        "dmesg.cpp",
 | 
			
		||||
        "integrator.ts"
 | 
			
		||||
    ],
 | 
			
		||||
    "testFiles": [
 | 
			
		||||
        "test.ts"
 | 
			
		||||
    ],
 | 
			
		||||
    "dalDTS": {
 | 
			
		||||
        "includeDirs": [
 | 
			
		||||
            "pxtapp"
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    "additionalFilePath": "../../node_modules/pxt-common-packages/libs/core---linux",
 | 
			
		||||
    "npmDependencies": {},
 | 
			
		||||
    "public": true,
 | 
			
		||||
    "dependencies": {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +0,0 @@
 | 
			
		||||
#ifndef __PXTCORE_H
 | 
			
		||||
#define __PXTCORE_H
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
namespace pxt {
 | 
			
		||||
void dmesg(const char *fmt, ...);
 | 
			
		||||
#define DMESG pxt::dmesg
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void itoa(int v, char *dst) {
 | 
			
		||||
 | 
			
		||||
    snprintf(dst, 30, "%d", v);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
@@ -85,10 +85,9 @@ void updateScreen(Image_ img) {
 | 
			
		||||
        lastImg = img;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (lastImg && lastImg->isDirty() && mappedFrameBuffer != MAP_FAILED) {
 | 
			
		||||
    if (lastImg && mappedFrameBuffer != MAP_FAILED) {
 | 
			
		||||
        if (lastImg->bpp() != 1 || lastImg->width() != LCD_WIDTH || lastImg->height() != LCD_HEIGHT)
 | 
			
		||||
            target_panic(906);
 | 
			
		||||
        lastImg->clearDirty();
 | 
			
		||||
        bitBufferToFrameBufferSwap(lastImg->pix(), mappedFrameBuffer);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -25,8 +25,8 @@ struct hci_dev_list_req {
 | 
			
		||||
    hci_dev_req dev_req[2];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static uint32_t bt_addr() {
 | 
			
		||||
    uint32_t res = -1;
 | 
			
		||||
static uint64_t bt_addr() {
 | 
			
		||||
    uint64_t res = -1;
 | 
			
		||||
 | 
			
		||||
    int fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
 | 
			
		||||
    if (fd < 0) {
 | 
			
		||||
@@ -50,11 +50,8 @@ static uint32_t bt_addr() {
 | 
			
		||||
        goto done;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    memcpy(&res, di.bdaddr, 4);
 | 
			
		||||
    res *= 0x1000193;
 | 
			
		||||
    res += di.bdaddr[4];
 | 
			
		||||
    res *= 0x1000193;
 | 
			
		||||
    res += di.bdaddr[5];
 | 
			
		||||
    res = 0;
 | 
			
		||||
    memcpy(&res, di.bdaddr, 6);
 | 
			
		||||
 | 
			
		||||
done:
 | 
			
		||||
    close(fd);
 | 
			
		||||
@@ -63,14 +60,10 @@ done:
 | 
			
		||||
 | 
			
		||||
namespace pxt {
 | 
			
		||||
 | 
			
		||||
int getSerialNumber() {
 | 
			
		||||
    static int serial;
 | 
			
		||||
 | 
			
		||||
    if (serial != 0)
 | 
			
		||||
        return serial;
 | 
			
		||||
 | 
			
		||||
    serial = bt_addr() & 0x7fffffff;
 | 
			
		||||
 | 
			
		||||
uint64_t getLongSerialNumber() {
 | 
			
		||||
    static uint64_t serial;
 | 
			
		||||
    if (serial == 0)
 | 
			
		||||
        serial = bt_addr();
 | 
			
		||||
    return serial;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -68,6 +68,12 @@ declare namespace control {
 | 
			
		||||
    /** Write data to DMESG debugging buffer. */
 | 
			
		||||
    //% shim=control::dmesg
 | 
			
		||||
    function dmesg(s: string): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determines if the USB has been enumerated.
 | 
			
		||||
     */
 | 
			
		||||
    //% shim=control::isUSBInitialized
 | 
			
		||||
    function isUSBInitialized(): boolean;
 | 
			
		||||
}
 | 
			
		||||
declare namespace serial {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user